Skip to content

Commit

Permalink
chore: merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev committed Jul 8, 2022
2 parents b5e7b1b + b835699 commit d65e896
Show file tree
Hide file tree
Showing 16 changed files with 147 additions and 557 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -35,7 +35,7 @@ In addition, Vite is highly extensible via its [Plugin API](https://vitejs.dev/g

## v3.0

Current Status: **Alpha** (for internal testing, not recommended for production)
Current Status: **Beta** (for internal testing, not recommended for production)

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.

Expand Down
2 changes: 2 additions & 0 deletions docs/config/server-options.md
Expand Up @@ -55,6 +55,8 @@ Enable TLS + HTTP/2. Note this downgrades to TLS only when the [`server.proxy` o

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

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.

## server.open

- **Type:** `boolean | string`
Expand Down
13 changes: 13 additions & 0 deletions docs/guide/migration.md
Expand Up @@ -87,6 +87,19 @@ You can use `?init` which is similar to the previous behavior.
})
```

### Automatic https certificate generation

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.
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.

```js
import basicSsl from '@vitejs/plugin-basic-ssl'

export default {
plugins: [basicSsl()]
}
```

## Experimental

### Using esbuild deps optimization at build time
Expand Down
340 changes: 1 addition & 339 deletions packages/vite/LICENSE.md

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion packages/vite/package.json
Expand Up @@ -101,7 +101,6 @@
"micromatch": "^4.0.5",
"mlly": "^0.5.4",
"mrmime": "^1.0.1",
"node-forge": "^1.3.1",
"okie": "^1.0.1",
"open": "^8.4.0",
"periscopic": "^3.0.4",
Expand Down
169 changes: 0 additions & 169 deletions packages/vite/src/node/certificate.ts

This file was deleted.

29 changes: 1 addition & 28 deletions packages/vite/src/node/http.ts
@@ -1,4 +1,4 @@
import fs, { promises as fsp } from 'node:fs'
import fs from 'node:fs'
import path from 'node:path'
import type {
Server as HttpServer,
Expand Down Expand Up @@ -134,9 +134,6 @@ export async function resolveHttpsConfig(
key: readFileIfExists(key),
pfx: readFileIfExists(pfx)
})
if (!httpsOption.key || !httpsOption.cert) {
httpsOption.cert = httpsOption.key = await getCertificate(cacheDir)
}
return httpsOption
}

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

async function getCertificate(cacheDir: string) {
const cachePath = path.join(cacheDir, '_cert.pem')

try {
const [stat, content] = await Promise.all([
fsp.stat(cachePath),
fsp.readFile(cachePath, 'utf8')
])

if (Date.now() - stat.ctime.valueOf() > 30 * 24 * 60 * 60 * 1000) {
throw new Error('cache is outdated.')
}

return content
} catch {
const content = (await import('./certificate')).createCertificate()
fsp
.mkdir(cacheDir, { recursive: true })
.then(() => fsp.writeFile(cachePath, content))
.catch(() => {})
return content
}
}

export async function httpServerStart(
httpServer: HttpServer,
serverOptions: {
Expand Down
27 changes: 22 additions & 5 deletions packages/vite/src/node/optimizer/scan.ts
Expand Up @@ -25,6 +25,8 @@ import type { PluginContainer } from '../server/pluginContainer'
import { createPluginContainer } from '../server/pluginContainer'
import { transformGlobImport } from '../plugins/importMetaGlob'

type ResolveIdOptions = Parameters<PluginContainer['resolveId']>[2]

const debug = createDebugger('vite:deps')

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

const resolve = async (id: string, importer?: string) => {
const resolve = async (
id: string,
importer?: string,
options?: ResolveIdOptions
) => {
const key = id + (importer && path.dirname(importer))
if (seen.has(key)) {
return seen.get(key)
Expand All @@ -172,6 +178,7 @@ function esbuildScanPlugin(
id,
importer && normalizePath(importer),
{
...options,
scan: true
}
)
Expand Down Expand Up @@ -316,12 +323,18 @@ function esbuildScanPlugin(
config.root,
resolve
)
)?.s.toString() || transpiledContents
)?.s.toString() || transpiledContents,
pluginData: {
htmlType: { loader }
}
}
} else {
scripts[key] = {
loader,
contents
contents,
pluginData: {
htmlType: { loader }
}
}
}

Expand Down Expand Up @@ -434,9 +447,13 @@ function esbuildScanPlugin(
{
filter: /.*/
},
async ({ path: id, importer }) => {
async ({ path: id, importer, pluginData }) => {
// use vite resolver to support urls and omitted extensions
const resolved = await resolve(id, importer)
const resolved = await resolve(id, importer, {
custom: {
depScan: { loader: pluginData?.htmlType?.loader }
}
})
if (resolved) {
if (shouldExternalizeDep(resolved, id) || !isScannable(resolved)) {
return externalUnlessEntry({ path: id })
Expand Down
5 changes: 4 additions & 1 deletion packages/vite/src/node/plugins/resolve.ts
Expand Up @@ -132,7 +132,10 @@ export function resolvePlugin(resolveOptions: InternalResolveOptions): Plugin {
}

if (importer) {
if (isTsRequest(importer)) {
if (
isTsRequest(importer) ||
resolveOpts.custom?.depScan?.loader?.startsWith('ts')
) {
options.isFromTsImporter = true
} else {
const moduleLang = this.getModuleInfo(importer)?.meta?.vite?.lang
Expand Down
46 changes: 46 additions & 0 deletions packages/vite/src/node/server/__tests__/pluginContainer.spec.ts
Expand Up @@ -100,6 +100,52 @@ describe('plugin container', () => {

expect.assertions(1)
})

it('can pass custom resolve opts between plugins', async () => {
const entryUrl = '/x.js'

const plugin1: Plugin = {
name: 'p1',
resolveId(id) {
if (id === entryUrl) {
return this.resolve('foobar', 'notreal', {
custom: { p1: 'success' },
isEntry: true
})
}
}
}

const plugin2: Plugin = {
name: 'p2',
resolveId(id, importer, opts) {
if (id === 'foobar') {
expect(importer).toBe('notreal')
expect(opts).toEqual(
expect.objectContaining({
custom: { p1: 'success' },
isEntry: true
})
)
return entryUrl
}
},
load(id) {
if (id === entryUrl) {
return null
}
}
}

const container = await getPluginContainer({
plugins: [plugin1, plugin2]
})

await moduleGraph.ensureEntryFromUrl(entryUrl, false)
await container.load(entryUrl)

expect.assertions(2)
})
})
})

Expand Down

0 comments on commit d65e896

Please sign in to comment.