Skip to content

Commit d65e896

Browse files
committed
chore: merge main
2 parents b5e7b1b + b835699 commit d65e896

File tree

16 files changed

+147
-557
lines changed

16 files changed

+147
-557
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ In addition, Vite is highly extensible via its [Plugin API](https://vitejs.dev/g
3535

3636
## v3.0
3737

38-
Current Status: **Alpha** (for internal testing, not recommended for production)
38+
Current Status: **Beta** (for internal testing, not recommended for production)
3939

4040
The `main` branch is now for v3.0, if you are looking for current stable releases, check the [`v2` branch](https://github.com/vitejs/vite/tree/v2) branch instead.
4141

docs/config/server-options.md

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ Enable TLS + HTTP/2. Note this downgrades to TLS only when the [`server.proxy` o
5555

5656
The value can also be an [options object](https://nodejs.org/api/https.html#https_https_createserver_options_requestlistener) passed to `https.createServer()`.
5757

58+
A valid certificate is needed. For a basic setup, you can add [@vitejs/plugin-basic-ssl](https://github.com/vitejs/vite-plugin-basic-ssl) to the project plugins, which will automatically create and cache a self-signed certificate. But we recommend creating your own certificates.
59+
5860
## server.open
5961

6062
- **Type:** `boolean | string`

docs/guide/migration.md

+13
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,19 @@ You can use `?init` which is similar to the previous behavior.
8787
})
8888
```
8989

90+
### Automatic https certificate generation
91+
92+
A valid certificate is needed when using `https`. In Vite v2, if no certificate was configured, a self-signed certificate was automatically created and cached.
93+
Since Vite v3, we recommend manually creating your certificates. If you still want to use the automatic generation from v2, this feature can be enabled back by adding [@vitejs/plugin-basic-ssl](https://github.com/vitejs/vite-plugin-basic-ssl) to the project plugins.
94+
95+
```js
96+
import basicSsl from '@vitejs/plugin-basic-ssl'
97+
98+
export default {
99+
plugins: [basicSsl()]
100+
}
101+
```
102+
90103
## Experimental
91104

92105
### Using esbuild deps optimization at build time

packages/vite/LICENSE.md

+1-339
Large diffs are not rendered by default.

packages/vite/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@
101101
"micromatch": "^4.0.5",
102102
"mlly": "^0.5.4",
103103
"mrmime": "^1.0.1",
104-
"node-forge": "^1.3.1",
105104
"okie": "^1.0.1",
106105
"open": "^8.4.0",
107106
"periscopic": "^3.0.4",

packages/vite/src/node/certificate.ts

-169
This file was deleted.

packages/vite/src/node/http.ts

+1-28
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import fs, { promises as fsp } from 'node:fs'
1+
import fs from 'node:fs'
22
import path from 'node:path'
33
import type {
44
Server as HttpServer,
@@ -134,9 +134,6 @@ export async function resolveHttpsConfig(
134134
key: readFileIfExists(key),
135135
pfx: readFileIfExists(pfx)
136136
})
137-
if (!httpsOption.key || !httpsOption.cert) {
138-
httpsOption.cert = httpsOption.key = await getCertificate(cacheDir)
139-
}
140137
return httpsOption
141138
}
142139

@@ -151,30 +148,6 @@ function readFileIfExists(value?: string | Buffer | any[]) {
151148
return value
152149
}
153150

154-
async function getCertificate(cacheDir: string) {
155-
const cachePath = path.join(cacheDir, '_cert.pem')
156-
157-
try {
158-
const [stat, content] = await Promise.all([
159-
fsp.stat(cachePath),
160-
fsp.readFile(cachePath, 'utf8')
161-
])
162-
163-
if (Date.now() - stat.ctime.valueOf() > 30 * 24 * 60 * 60 * 1000) {
164-
throw new Error('cache is outdated.')
165-
}
166-
167-
return content
168-
} catch {
169-
const content = (await import('./certificate')).createCertificate()
170-
fsp
171-
.mkdir(cacheDir, { recursive: true })
172-
.then(() => fsp.writeFile(cachePath, content))
173-
.catch(() => {})
174-
return content
175-
}
176-
}
177-
178151
export async function httpServerStart(
179152
httpServer: HttpServer,
180153
serverOptions: {

packages/vite/src/node/optimizer/scan.ts

+22-5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import type { PluginContainer } from '../server/pluginContainer'
2525
import { createPluginContainer } from '../server/pluginContainer'
2626
import { transformGlobImport } from '../plugins/importMetaGlob'
2727

28+
type ResolveIdOptions = Parameters<PluginContainer['resolveId']>[2]
29+
2830
const debug = createDebugger('vite:deps')
2931

3032
const htmlTypesRE = /\.(html|vue|svelte|astro)$/
@@ -163,7 +165,11 @@ function esbuildScanPlugin(
163165
): Plugin {
164166
const seen = new Map<string, string | undefined>()
165167

166-
const resolve = async (id: string, importer?: string) => {
168+
const resolve = async (
169+
id: string,
170+
importer?: string,
171+
options?: ResolveIdOptions
172+
) => {
167173
const key = id + (importer && path.dirname(importer))
168174
if (seen.has(key)) {
169175
return seen.get(key)
@@ -172,6 +178,7 @@ function esbuildScanPlugin(
172178
id,
173179
importer && normalizePath(importer),
174180
{
181+
...options,
175182
scan: true
176183
}
177184
)
@@ -316,12 +323,18 @@ function esbuildScanPlugin(
316323
config.root,
317324
resolve
318325
)
319-
)?.s.toString() || transpiledContents
326+
)?.s.toString() || transpiledContents,
327+
pluginData: {
328+
htmlType: { loader }
329+
}
320330
}
321331
} else {
322332
scripts[key] = {
323333
loader,
324-
contents
334+
contents,
335+
pluginData: {
336+
htmlType: { loader }
337+
}
325338
}
326339
}
327340

@@ -434,9 +447,13 @@ function esbuildScanPlugin(
434447
{
435448
filter: /.*/
436449
},
437-
async ({ path: id, importer }) => {
450+
async ({ path: id, importer, pluginData }) => {
438451
// use vite resolver to support urls and omitted extensions
439-
const resolved = await resolve(id, importer)
452+
const resolved = await resolve(id, importer, {
453+
custom: {
454+
depScan: { loader: pluginData?.htmlType?.loader }
455+
}
456+
})
440457
if (resolved) {
441458
if (shouldExternalizeDep(resolved, id) || !isScannable(resolved)) {
442459
return externalUnlessEntry({ path: id })

packages/vite/src/node/plugins/resolve.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,10 @@ export function resolvePlugin(resolveOptions: InternalResolveOptions): Plugin {
132132
}
133133

134134
if (importer) {
135-
if (isTsRequest(importer)) {
135+
if (
136+
isTsRequest(importer) ||
137+
resolveOpts.custom?.depScan?.loader?.startsWith('ts')
138+
) {
136139
options.isFromTsImporter = true
137140
} else {
138141
const moduleLang = this.getModuleInfo(importer)?.meta?.vite?.lang

packages/vite/src/node/server/__tests__/pluginContainer.spec.ts

+46
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,52 @@ describe('plugin container', () => {
100100

101101
expect.assertions(1)
102102
})
103+
104+
it('can pass custom resolve opts between plugins', async () => {
105+
const entryUrl = '/x.js'
106+
107+
const plugin1: Plugin = {
108+
name: 'p1',
109+
resolveId(id) {
110+
if (id === entryUrl) {
111+
return this.resolve('foobar', 'notreal', {
112+
custom: { p1: 'success' },
113+
isEntry: true
114+
})
115+
}
116+
}
117+
}
118+
119+
const plugin2: Plugin = {
120+
name: 'p2',
121+
resolveId(id, importer, opts) {
122+
if (id === 'foobar') {
123+
expect(importer).toBe('notreal')
124+
expect(opts).toEqual(
125+
expect.objectContaining({
126+
custom: { p1: 'success' },
127+
isEntry: true
128+
})
129+
)
130+
return entryUrl
131+
}
132+
},
133+
load(id) {
134+
if (id === entryUrl) {
135+
return null
136+
}
137+
}
138+
}
139+
140+
const container = await getPluginContainer({
141+
plugins: [plugin1, plugin2]
142+
})
143+
144+
await moduleGraph.ensureEntryFromUrl(entryUrl, false)
145+
await container.load(entryUrl)
146+
147+
expect.assertions(2)
148+
})
103149
})
104150
})
105151

0 commit comments

Comments
 (0)