From af2df6baebe743b6c1d3d363d3ce4c77d4a49c09 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Sat, 9 Oct 2021 12:25:54 +0800 Subject: [PATCH] build(deps): bump vite from 2.6.3 to 2.6.5 --- package.json | 4 +- packages/playground/ssr/package.json | 2 +- packages/playground/ssr/yarn.lock | 2 +- packages/uni-h5-vite/src/plugin/index.ts | 1 + packages/vite-plugin-uni/src/cli/logger.ts | 88 ---------------------- packages/vite-plugin-uni/src/cli/server.ts | 43 +---------- yarn.lock | 4 +- 7 files changed, 11 insertions(+), 133 deletions(-) delete mode 100644 packages/vite-plugin-uni/src/cli/logger.ts diff --git a/package.json b/package.json index c971504a9..06d0c3498 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "packages/*" ], "scripts": { - "build": "node scripts/build.js && npm run test", + "build": "node scripts/build.js", "build:h5": "node scripts/build.js uni-app uni-cli-shared uni-h5 uni-i18n uni-stat uni-shared uni-h5-vite vite-plugin-uni", "build:app": "node scripts/build.js uni-app-plus uni-app-vite uni-app-vue uni-cli-nvue", "build:mp": "node scripts/build.js uni-mp-vue uni-mp-alipay uni-mp-baidu uni-mp-qq uni-mp-toutiao uni-mp-weixin uni-mp-kuaishou uni-quickapp-webview", @@ -96,7 +96,7 @@ "semver": "^7.3.4", "ts-jest": "^27.0.3", "typescript": "^4.4.3", - "vite": "^2.6.3", + "vite": "^2.6.5", "vue": "^3.2.20", "yorkie": "^2.0.0" }, diff --git a/packages/playground/ssr/package.json b/packages/playground/ssr/package.json index 3e898ebdd..6f06de578 100644 --- a/packages/playground/ssr/package.json +++ b/packages/playground/ssr/package.json @@ -32,6 +32,6 @@ "compression": "^1.7.4", "cypress": "^7.3.0", "serve-static": "^1.14.1", - "vite": "^2.6.3" + "vite": "^2.6.5" } } diff --git a/packages/playground/ssr/yarn.lock b/packages/playground/ssr/yarn.lock index 0a310b8b5..562a27c6f 100644 --- a/packages/playground/ssr/yarn.lock +++ b/packages/playground/ssr/yarn.lock @@ -2205,7 +2205,7 @@ verror@1.10.0: core-util-is "1.0.2" extsprintf "^1.2.0" -vite@^2.6.3: +vite@^2.6.5: version "2.6.5" resolved "https://registry.yarnpkg.com/vite/-/vite-2.6.5.tgz#c4d25972e2f7371e682da86828722ddf5126f3d1" integrity sha512-vavXMChDUb4Oh4YunrK9BrH5Ox74cu0eOp0VuyI/iqFz1FqbWD72So2c9I87lLL2n0+6tFPV5ijow60KrtxuZg== diff --git a/packages/uni-h5-vite/src/plugin/index.ts b/packages/uni-h5-vite/src/plugin/index.ts index 9b195ea8b..500647ad3 100644 --- a/packages/uni-h5-vite/src/plugin/index.ts +++ b/packages/uni-h5-vite/src/plugin/index.ts @@ -60,6 +60,7 @@ export const UniH5Plugin: UniVitePlugin = { }, define: createDefine(env.command, config), server: { + host: true, fs: { strict: false, }, diff --git a/packages/vite-plugin-uni/src/cli/logger.ts b/packages/vite-plugin-uni/src/cli/logger.ts deleted file mode 100644 index dcfe51975..000000000 --- a/packages/vite-plugin-uni/src/cli/logger.ts +++ /dev/null @@ -1,88 +0,0 @@ -import os from 'os' -import { AddressInfo, Server } from 'net' -import chalk from 'chalk' -import { Logger, ResolvedConfig } from 'vite' -export function printHttpServerUrls( - server: Server, - config: ResolvedConfig -): void { - const address = server.address() - const isAddressInfo = (x: any): x is AddressInfo => x?.address - if (isAddressInfo(address)) { - const hostname = resolveHostname(true /*config.server.host*/) - const protocol = config.server.https ? 'https' : 'http' - printServerUrls( - hostname, - protocol, - address.port, - config.base, - config.logger.info - ) - } -} - -function printServerUrls( - hostname: Hostname, - protocol: string, - port: number, - base: string, - info: Logger['info'] -): void { - if (hostname.host === '127.0.0.1') { - const url = `${protocol}://${hostname.name}:${chalk.bold(port)}${base}` - info(` > Local: ${chalk.cyan(url)}`) - if (hostname.name !== '127.0.0.1') { - info(` > Network: ${chalk.dim('use `--host` to expose')}`) - } - } else { - Object.values(os.networkInterfaces()) - .flatMap((nInterface) => nInterface ?? []) - .filter((detail) => detail && detail.address && detail.family === 'IPv4') - .map((detail) => { - const type = detail.address.includes('127.0.0.1') - ? 'Local: ' - : 'Network: ' - const host = detail.address.replace('127.0.0.1', hostname.name) - const url = `${protocol}://${host}:${chalk.bold(port)}${base}` - return ` > ${type} ${chalk.cyan(url)}` - }) - .forEach((msg) => info(msg)) - } -} - -export interface Hostname { - // undefined sets the default behaviour of server.listen - host: string | undefined - // resolve to localhost when possible - name: string -} - -export function resolveHostname( - optionsHost: string | boolean | undefined -): Hostname { - let host: string | undefined - if ( - optionsHost === undefined || - optionsHost === false || - optionsHost === 'localhost' - ) { - // Use a secure default - host = '127.0.0.1' - } else if (optionsHost === true) { - // If passed --host in the CLI without arguments - host = undefined // undefined typically means 0.0.0.0 or :: (listen on all IPs) - } else { - host = optionsHost - } - - // Set host name to localhost when possible, unless the user explicitly asked for '127.0.0.1' - const name = - (optionsHost !== '127.0.0.1' && host === '127.0.0.1') || - host === '0.0.0.0' || - host === '::' || - host === undefined - ? 'localhost' - : host - - return { host, name } -} diff --git a/packages/vite-plugin-uni/src/cli/server.ts b/packages/vite-plugin-uni/src/cli/server.ts index 8b20d2647..9f23f298c 100644 --- a/packages/vite-plugin-uni/src/cli/server.ts +++ b/packages/vite-plugin-uni/src/cli/server.ts @@ -1,4 +1,3 @@ -import os from 'os' import fs from 'fs' import path from 'path' import chalk from 'chalk' @@ -8,11 +7,10 @@ import { ServerOptions, } from 'vite' import express from 'express' -import { hasOwn } from '@vue/shared' +import { printHttpServerUrls } from 'vite' import { parseManifestJson } from '@dcloudio/uni-cli-shared' import { CliOptions } from '.' import { addConfigFile, cleanOptions } from './utils' -import { printHttpServerUrls } from './logger' export async function createServer(options: CliOptions & ServerOptions) { const server = await createViteServer( @@ -35,7 +33,7 @@ export async function createServer(options: CliOptions & ServerOptions) { } ) - printHttpServerUrls(server.httpServer!, server.config) + server.printUrls() } export async function createSSRServer(options: CliOptions & ServerOptions) { @@ -61,7 +59,6 @@ export async function createSSRServer(options: CliOptions & ServerOptions) { ) // use vite's connect instance as middleware app.use(vite.middlewares) - app.use('*', async (req, res) => { try { const { h5 } = parseManifestJson(process.env.UNI_INPUT_DIR) @@ -100,11 +97,7 @@ export async function createSSRServer(options: CliOptions & ServerOptions) { const logger = createLogger(options.logLevel) const serverOptions = vite.config.server || {} - const protocol = ( - hasOwn(options, 'https') ? options.https : serverOptions.https - ) - ? 'https' - : 'http' + let port = options.port || serverOptions.port || 3000 let hostname: string | undefined if (options.host === 'localhost') { @@ -118,35 +111,7 @@ export async function createSSRServer(options: CliOptions & ServerOptions) { } return new Promise((resolve, reject) => { const onSuccess = () => { - const interfaces = os.networkInterfaces() - const locals: string[] = [] - const networks: string[] = [] - Object.keys(interfaces).forEach((key) => - (interfaces[key] || []) - .filter((details) => details.family === 'IPv4') - .forEach((detail) => { - if (detail.address.includes('127.0.0.1')) { - locals.push(detail.address) - } else { - networks.push(detail.address) - } - }) - ) - locals.forEach((host) => { - const url = `${protocol}://${host}:${chalk.bold(port)}${ - vite.config.base - }` - logger.info(` - Local: ${chalk.cyan(url)}`) - }) - const networksLen = networks.length - 1 - networks.forEach((host, index) => { - const url = `${protocol}://${host}:${chalk.bold(port)}${ - vite.config.base - }` - logger.info( - ` ${index === networksLen ? '-' : '>'} Network: ${chalk.cyan(url)}` - ) - }) + printHttpServerUrls(server, vite.config) resolve(server) } const onError = (e: Error & { code?: string }) => { diff --git a/yarn.lock b/yarn.lock index 9e4ab7ce9..c7aba90f6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2770,7 +2770,7 @@ html-tags "^3.1.0" svg-tags "^1.0.0" -"@vue/compiler-core@3.2.20": +"@vue/compiler-core@3.2.20", "@vue/compiler-core@^3.2.20": version "3.2.20" resolved "https://registry.yarnpkg.com/@vue/compiler-core/-/compiler-core-3.2.20.tgz#af5a3c5237818835b0d0be837eb5885a8d21c160" integrity sha512-vcEXlKXoPwBXFP5aUTHN9GTZaDfwCofa9Yu9bbW2C5O/QSa9Esdt7OG4+0RRd3EHEMxUvEdj4RZrd/KpQeiJbA== @@ -10229,7 +10229,7 @@ verror@1.10.0: core-util-is "1.0.2" extsprintf "^1.2.0" -vite@^2.6.3: +vite@^2.6.5: version "2.6.5" resolved "https://registry.yarnpkg.com/vite/-/vite-2.6.5.tgz#c4d25972e2f7371e682da86828722ddf5126f3d1" integrity sha512-vavXMChDUb4Oh4YunrK9BrH5Ox74cu0eOp0VuyI/iqFz1FqbWD72So2c9I87lLL2n0+6tFPV5ijow60KrtxuZg== -- GitLab