vite 2.6.0-beta.0 → 2.6.0-beta.4

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.

Potentially problematic release.


This version of vite might be problematic. Click here for more details.

Files changed (110) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/LICENSE.md +161 -3011
  3. package/bin/vite.js +2 -1
  4. package/dist/node/chunks/{dep-91aa74e8.js → dep-1e0a75a8.js} +58 -32
  5. package/dist/node/chunks/dep-1e0a75a8.js.map +1 -0
  6. package/dist/node/chunks/{dep-e36486f6.js → dep-ac1b4bf9.js} +1 -1
  7. package/dist/node/chunks/dep-ac1b4bf9.js.map +1 -0
  8. package/dist/node/chunks/{dep-c7e510f9.js → dep-ba6b30a0.js} +27538 -4953
  9. package/dist/node/chunks/dep-ba6b30a0.js.map +1 -0
  10. package/dist/node/chunks/{dep-11213a75.js → dep-c4cf6e92.js} +19 -6
  11. package/dist/node/chunks/dep-c4cf6e92.js.map +1 -0
  12. package/dist/node/chunks/{dep-eb6ef720.js → dep-d574094c.js} +18 -5
  13. package/dist/node/chunks/dep-d574094c.js.map +1 -0
  14. package/dist/node/chunks/{dep-0d2f9464.js → dep-e39b05d6.js} +18 -5
  15. package/dist/node/chunks/dep-e39b05d6.js.map +1 -0
  16. package/dist/node/cli.js +60 -23992
  17. package/dist/node/cli.js.map +1 -1
  18. package/dist/node/index.d.ts +26 -8
  19. package/dist/node/index.js +18 -15
  20. package/dist/node/index.js.map +1 -1
  21. package/dist/node/terser.js +102 -55
  22. package/package.json +28 -13
  23. package/types/package.json +3 -0
  24. package/api-extractor.json +0 -54
  25. package/dist/node/chunks/dep-0d2f9464.js.map +0 -1
  26. package/dist/node/chunks/dep-11213a75.js.map +0 -1
  27. package/dist/node/chunks/dep-91aa74e8.js.map +0 -1
  28. package/dist/node/chunks/dep-c7e510f9.js.map +0 -1
  29. package/dist/node/chunks/dep-e36486f6.js.map +0 -1
  30. package/dist/node/chunks/dep-eb6ef720.js.map +0 -1
  31. package/dist/node/terser.js.map +0 -1
  32. package/rollup.config.js +0 -389
  33. package/scripts/patchTypes.js +0 -70
  34. package/src/node/__tests__/asset.spec.ts +0 -156
  35. package/src/node/__tests__/build.spec.ts +0 -67
  36. package/src/node/__tests__/config.spec.ts +0 -166
  37. package/src/node/__tests__/packages/name/package.json +0 -3
  38. package/src/node/__tests__/packages/noname/package.json +0 -1
  39. package/src/node/__tests__/plugins/css.spec.ts +0 -116
  40. package/src/node/__tests__/scan.spec.ts +0 -118
  41. package/src/node/__tests__/utils.spec.ts +0 -40
  42. package/src/node/build.ts +0 -783
  43. package/src/node/cli.ts +0 -239
  44. package/src/node/config.ts +0 -1033
  45. package/src/node/constants.ts +0 -87
  46. package/src/node/importGlob.ts +0 -173
  47. package/src/node/index.ts +0 -88
  48. package/src/node/logger.ts +0 -167
  49. package/src/node/optimizer/esbuildDepPlugin.ts +0 -216
  50. package/src/node/optimizer/index.ts +0 -410
  51. package/src/node/optimizer/registerMissing.ts +0 -102
  52. package/src/node/optimizer/scan.ts +0 -457
  53. package/src/node/plugin.ts +0 -138
  54. package/src/node/plugins/asset.ts +0 -365
  55. package/src/node/plugins/assetImportMetaUrl.ts +0 -99
  56. package/src/node/plugins/clientInjections.ts +0 -72
  57. package/src/node/plugins/css.ts +0 -1279
  58. package/src/node/plugins/dataUri.ts +0 -64
  59. package/src/node/plugins/define.ts +0 -107
  60. package/src/node/plugins/esbuild.ts +0 -280
  61. package/src/node/plugins/html.ts +0 -673
  62. package/src/node/plugins/importAnalysis.ts +0 -614
  63. package/src/node/plugins/importAnalysisBuild.ts +0 -334
  64. package/src/node/plugins/index.ts +0 -69
  65. package/src/node/plugins/json.ts +0 -75
  66. package/src/node/plugins/loadFallback.ts +0 -19
  67. package/src/node/plugins/manifest.ts +0 -123
  68. package/src/node/plugins/modulePreloadPolyfill.ts +0 -100
  69. package/src/node/plugins/preAlias.ts +0 -22
  70. package/src/node/plugins/reporter.ts +0 -244
  71. package/src/node/plugins/resolve.ts +0 -925
  72. package/src/node/plugins/terser.ts +0 -40
  73. package/src/node/plugins/wasm.ts +0 -72
  74. package/src/node/plugins/worker.ts +0 -117
  75. package/src/node/preview.ts +0 -82
  76. package/src/node/server/__tests__/fixtures/none/nested/package.json +0 -3
  77. package/src/node/server/__tests__/fixtures/pnpm/nested/package.json +0 -3
  78. package/src/node/server/__tests__/fixtures/pnpm/package.json +0 -3
  79. package/src/node/server/__tests__/fixtures/pnpm/pnpm-workspace.yaml +0 -0
  80. package/src/node/server/__tests__/fixtures/yarn/nested/package.json +0 -3
  81. package/src/node/server/__tests__/fixtures/yarn/package.json +0 -6
  82. package/src/node/server/__tests__/search-root.spec.ts +0 -31
  83. package/src/node/server/hmr.ts +0 -489
  84. package/src/node/server/http.ts +0 -198
  85. package/src/node/server/index.ts +0 -705
  86. package/src/node/server/middlewares/base.ts +0 -52
  87. package/src/node/server/middlewares/error.ts +0 -98
  88. package/src/node/server/middlewares/indexHtml.ts +0 -170
  89. package/src/node/server/middlewares/proxy.ts +0 -124
  90. package/src/node/server/middlewares/spaFallback.ts +0 -32
  91. package/src/node/server/middlewares/static.ts +0 -153
  92. package/src/node/server/middlewares/time.ts +0 -18
  93. package/src/node/server/middlewares/transform.ts +0 -196
  94. package/src/node/server/moduleGraph.ts +0 -200
  95. package/src/node/server/openBrowser.ts +0 -101
  96. package/src/node/server/pluginContainer.ts +0 -546
  97. package/src/node/server/searchRoot.ts +0 -70
  98. package/src/node/server/send.ts +0 -54
  99. package/src/node/server/sourcemap.ts +0 -54
  100. package/src/node/server/transformRequest.ts +0 -168
  101. package/src/node/server/ws.ts +0 -131
  102. package/src/node/ssr/__tests__/ssrTransform.spec.ts +0 -309
  103. package/src/node/ssr/ssrExternal.ts +0 -161
  104. package/src/node/ssr/ssrManifestPlugin.ts +0 -53
  105. package/src/node/ssr/ssrModuleLoader.ts +0 -214
  106. package/src/node/ssr/ssrStacktrace.ts +0 -75
  107. package/src/node/ssr/ssrTransform.ts +0 -452
  108. package/src/node/tsconfig.json +0 -14
  109. package/src/node/utils.ts +0 -565
  110. package/tsconfig.base.json +0 -11
@@ -1,40 +0,0 @@
1
- import { Plugin } from '../plugin'
2
- import { Worker } from 'okie'
3
- import { Terser } from 'types/terser'
4
-
5
- export function terserPlugin(options: Terser.MinifyOptions): Plugin {
6
- const worker = new Worker(
7
- (basedir: string, code: string, options: Terser.MinifyOptions) => {
8
- // when vite is linked, the worker thread won't share the same resolve
9
- // root with vite itself, so we have to pass in the basedir and resolve
10
- // terser first.
11
- // eslint-disable-next-line node/no-restricted-require
12
- const terserPath = require.resolve('terser', {
13
- paths: [basedir]
14
- })
15
- return require(terserPath).minify(code, options) as Terser.MinifyOutput
16
- }
17
- )
18
-
19
- return {
20
- name: 'vite:terser',
21
-
22
- async renderChunk(code, _chunk, outputOptions) {
23
- const res = await worker.run(__dirname, code, {
24
- safari10: true,
25
- ...options,
26
- sourceMap: !!outputOptions.sourcemap,
27
- module: outputOptions.format.startsWith('es'),
28
- toplevel: outputOptions.format === 'cjs'
29
- })
30
- return {
31
- code: res.code!,
32
- map: res.map as any
33
- }
34
- },
35
-
36
- closeBundle() {
37
- worker.stop()
38
- }
39
- }
40
- }
@@ -1,72 +0,0 @@
1
- import { ResolvedConfig } from '../config'
2
- import { Plugin } from '../plugin'
3
- import { fileToUrl } from './asset'
4
-
5
- const wasmHelperId = '/__vite-wasm-helper'
6
-
7
- const wasmHelper = async (opts = {}, url: string) => {
8
- let result
9
- if (url.startsWith('data:')) {
10
- // @ts-ignore
11
- const binaryString = atob(url.replace(/^data:.*?base64,/, ''))
12
- const bytes = new Uint8Array(binaryString.length)
13
- for (let i = 0; i < binaryString.length; i++) {
14
- bytes[i] = binaryString.charCodeAt(i)
15
- }
16
- // @ts-ignore
17
- result = await WebAssembly.instantiate(bytes, opts)
18
- } else {
19
- // https://github.com/mdn/webassembly-examples/issues/5
20
- // WebAssembly.instantiateStreaming requires the server to provide the
21
- // correct MIME type for .wasm files, which unfortunately doesn't work for
22
- // a lot of static file servers, so we just work around it by getting the
23
- // raw buffer.
24
- // @ts-ignore
25
- const response = await fetch(url)
26
- const contentType = response.headers.get('Content-Type') || ''
27
- if (
28
- // @ts-ignore
29
- 'instantiateStreaming' in WebAssembly &&
30
- contentType.startsWith('application/wasm')
31
- ) {
32
- // @ts-ignore
33
- result = await WebAssembly.instantiateStreaming(response, opts)
34
- } else {
35
- const buffer = await response.arrayBuffer()
36
- // @ts-ignore
37
- result = await WebAssembly.instantiate(buffer, opts)
38
- }
39
- }
40
- return result.instance.exports
41
- }
42
-
43
- const wasmHelperCode = wasmHelper.toString()
44
-
45
- export const wasmPlugin = (config: ResolvedConfig): Plugin => {
46
- return {
47
- name: 'vite:wasm',
48
-
49
- resolveId(id) {
50
- if (id === wasmHelperId) {
51
- return id
52
- }
53
- },
54
-
55
- async load(id) {
56
- if (id === wasmHelperId) {
57
- return `export default ${wasmHelperCode}`
58
- }
59
-
60
- if (!id.endsWith('.wasm')) {
61
- return
62
- }
63
-
64
- const url = await fileToUrl(id, config, this)
65
-
66
- return `
67
- import initWasm from "${wasmHelperId}"
68
- export default opts => initWasm(opts, ${JSON.stringify(url)})
69
- `
70
- }
71
- }
72
- }
@@ -1,117 +0,0 @@
1
- import { ResolvedConfig } from '../config'
2
- import { Plugin } from '../plugin'
3
- import { resolvePlugins } from '../plugins'
4
- import { parse as parseUrl, URLSearchParams } from 'url'
5
- import { fileToUrl, getAssetHash } from './asset'
6
- import { cleanUrl, injectQuery } from '../utils'
7
- import Rollup from 'rollup'
8
- import { ENV_PUBLIC_PATH } from '../constants'
9
- import path from 'path'
10
- import { onRollupWarning } from '../build'
11
-
12
- function parseWorkerRequest(id: string): Record<string, string> | null {
13
- const { search } = parseUrl(id)
14
- if (!search) {
15
- return null
16
- }
17
- return Object.fromEntries(new URLSearchParams(search.slice(1)))
18
- }
19
-
20
- const WorkerFileId = 'worker_file'
21
-
22
- export function webWorkerPlugin(config: ResolvedConfig): Plugin {
23
- const isBuild = config.command === 'build'
24
-
25
- return {
26
- name: 'vite:worker',
27
-
28
- load(id) {
29
- if (isBuild) {
30
- const parsedQuery = parseWorkerRequest(id)
31
- if (
32
- parsedQuery &&
33
- (parsedQuery.worker ?? parsedQuery.sharedworker) != null
34
- ) {
35
- return ''
36
- }
37
- }
38
- },
39
-
40
- async transform(_, id) {
41
- const query = parseWorkerRequest(id)
42
- if (query && query[WorkerFileId] != null) {
43
- return {
44
- code: `import '${ENV_PUBLIC_PATH}'\n` + _
45
- }
46
- }
47
- if (
48
- query == null ||
49
- (query && (query.worker ?? query.sharedworker) == null)
50
- ) {
51
- return
52
- }
53
-
54
- let url: string
55
- if (isBuild) {
56
- // bundle the file as entry to support imports
57
- const rollup = require('rollup') as typeof Rollup
58
- const bundle = await rollup.rollup({
59
- input: cleanUrl(id),
60
- plugins: await resolvePlugins({ ...config }, [], [], []),
61
- onwarn(warning, warn) {
62
- onRollupWarning(warning, warn, config)
63
- }
64
- })
65
- let code: string
66
- try {
67
- const { output } = await bundle.generate({
68
- format: 'iife',
69
- sourcemap: config.build.sourcemap
70
- })
71
- code = output[0].code
72
- } finally {
73
- await bundle.close()
74
- }
75
- const content = Buffer.from(code)
76
- if (query.inline != null) {
77
- // inline as blob data url
78
- return `const encodedJs = "${content.toString('base64')}";
79
- const blob = typeof window !== "undefined" && window.Blob && new Blob([atob(encodedJs)], { type: "text/javascript;charset=utf-8" });
80
- export default function WorkerWrapper() {
81
- const objURL = blob && (window.URL || window.webkitURL).createObjectURL(blob);
82
- try {
83
- return objURL ? new Worker(objURL) : new Worker("data:application/javascript;base64," + encodedJs, {type: "module"});
84
- } finally {
85
- objURL && (window.URL || window.webkitURL).revokeObjectURL(objURL);
86
- }
87
- }`
88
- } else {
89
- const basename = path.parse(cleanUrl(id)).name
90
- const contentHash = getAssetHash(content)
91
- const fileName = path.posix.join(
92
- config.build.assetsDir,
93
- `${basename}.${contentHash}.js`
94
- )
95
- url = `__VITE_ASSET__${this.emitFile({
96
- fileName,
97
- type: 'asset',
98
- source: code
99
- })}__`
100
- }
101
- } else {
102
- url = await fileToUrl(cleanUrl(id), config, this)
103
- url = injectQuery(url, WorkerFileId)
104
- }
105
-
106
- const workerConstructor =
107
- query.sharedworker != null ? 'SharedWorker' : 'Worker'
108
- const workerOptions = { type: 'module' }
109
-
110
- return `export default function WorkerWrapper() {
111
- return new ${workerConstructor}(${JSON.stringify(
112
- url
113
- )}, ${JSON.stringify(workerOptions, null, 2)})
114
- }`
115
- }
116
- }
117
- }
@@ -1,82 +0,0 @@
1
- import path from 'path'
2
- import sirv from 'sirv'
3
- import chalk from 'chalk'
4
- import connect from 'connect'
5
- import compression from 'compression'
6
- import { ResolvedConfig, ServerOptions } from '.'
7
- import { Connect } from 'types/connect'
8
- import {
9
- resolveHttpsConfig,
10
- resolveHttpServer,
11
- httpServerStart
12
- } from './server/http'
13
- import { openBrowser } from './server/openBrowser'
14
- import corsMiddleware from 'cors'
15
- import { proxyMiddleware } from './server/middlewares/proxy'
16
- import { printServerUrls } from './logger'
17
- import { resolveHostname } from './utils'
18
-
19
- export async function preview(
20
- config: ResolvedConfig,
21
- serverOptions: Pick<ServerOptions, 'port' | 'host'>
22
- ): Promise<void> {
23
- const app = connect() as Connect.Server
24
- const httpServer = await resolveHttpServer(
25
- config.server,
26
- app,
27
- await resolveHttpsConfig(config)
28
- )
29
-
30
- // cors
31
- const { cors } = config.server
32
- if (cors !== false) {
33
- app.use(corsMiddleware(typeof cors === 'boolean' ? {} : cors))
34
- }
35
-
36
- // proxy
37
- if (config.server.proxy) {
38
- app.use(proxyMiddleware(httpServer, config))
39
- }
40
-
41
- app.use(compression())
42
-
43
- const distDir = path.resolve(config.root, config.build.outDir)
44
- app.use(
45
- config.base,
46
- sirv(distDir, {
47
- etag: true,
48
- dev: true,
49
- single: true
50
- })
51
- )
52
-
53
- const options = config.server
54
- const hostname = resolveHostname(serverOptions.host ?? options.host)
55
- const port = serverOptions.port ?? 5000
56
- const protocol = options.https ? 'https' : 'http'
57
- const logger = config.logger
58
- const base = config.base
59
-
60
- const serverPort = await httpServerStart(httpServer, {
61
- port,
62
- strictPort: options.strictPort,
63
- host: hostname.host,
64
- logger
65
- })
66
-
67
- logger.info(
68
- chalk.cyan(`\n vite v${require('vite/package.json').version}`) +
69
- chalk.green(` build preview server running at:\n`)
70
- )
71
-
72
- printServerUrls(hostname, protocol, serverPort, base, logger.info)
73
-
74
- if (options.open) {
75
- const path = typeof options.open === 'string' ? options.open : base
76
- openBrowser(
77
- `${protocol}://${hostname.name}:${serverPort}${path}`,
78
- true,
79
- logger
80
- )
81
- }
82
- }
@@ -1,3 +0,0 @@
1
- {
2
- "private": true
3
- }
@@ -1,3 +0,0 @@
1
- {
2
- "private": true
3
- }
@@ -1,3 +0,0 @@
1
- {
2
- "private": true
3
- }
@@ -1,3 +0,0 @@
1
- {
2
- "private": true
3
- }
@@ -1,6 +0,0 @@
1
- {
2
- "private": true,
3
- "workspaces": [
4
- "nested"
5
- ]
6
- }
@@ -1,31 +0,0 @@
1
- import { searchForWorkspaceRoot } from '../searchRoot'
2
- import { resolve } from 'path'
3
-
4
- describe('searchForWorkspaceRoot', () => {
5
- test('pnpm', () => {
6
- const resolved = searchForWorkspaceRoot(
7
- resolve(__dirname, 'fixtures/pnpm/nested')
8
- )
9
- expect(resolved).toBe(resolve(__dirname, 'fixtures/pnpm'))
10
- })
11
-
12
- test('yarn', () => {
13
- const resolved = searchForWorkspaceRoot(
14
- resolve(__dirname, 'fixtures/yarn/nested')
15
- )
16
- expect(resolved).toBe(resolve(__dirname, 'fixtures/yarn'))
17
- })
18
-
19
- test('yarn at root', () => {
20
- const resolved = searchForWorkspaceRoot(resolve(__dirname, 'fixtures/yarn'))
21
- expect(resolved).toBe(resolve(__dirname, 'fixtures/yarn'))
22
- })
23
-
24
- test('none', () => {
25
- const resolved = searchForWorkspaceRoot(
26
- resolve(__dirname, 'fixtures/none/nested')
27
- )
28
- // resolved to vite repo's root
29
- expect(resolved).toBe(resolve(__dirname, '../../../../../..'))
30
- })
31
- })