Skip to content

Commit

Permalink
fix: Partial support for Vite 2.6.0 - Print server info
Browse files Browse the repository at this point in the history
  • Loading branch information
frandiox committed Oct 11, 2021
1 parent eaf6ca4 commit 08067b6
Show file tree
Hide file tree
Showing 10 changed files with 339 additions and 545 deletions.
2 changes: 1 addition & 1 deletion examples/react-apollo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
},
"devDependencies": {
"@vitejs/plugin-react": "^1.0.2",
"vite": "^2.5.0"
"vite": "2.6.x"
}
}
2 changes: 1 addition & 1 deletion examples/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
},
"devDependencies": {
"@vitejs/plugin-react": "^1.0.2",
"vite": "^2.5.0"
"vite": "2.6.x"
}
}
2 changes: 1 addition & 1 deletion examples/vanilla/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"serve:node": "node ../node-server/index vue"
},
"dependencies": {
"vite": "^2.5.0"
"vite": "2.6.x"
}
}
670 changes: 151 additions & 519 deletions examples/vanilla/yarn.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions examples/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"@vitejs/plugin-vue": "^1.1.4",
"@vue/compiler-sfc": "^3.2.0",
"@vueuse/head": "^0.6.0",
"vite": "^2.5.0",
"vite": "2.6.x",
"vue": "^3.2.0",
"vue-router": "^4.0.0"
}
}
}
7 changes: 7 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#!/usr/bin/env node

// @ts-ignore
if (!globalThis.__ssr_start_time) {
const { performance } = require('perf_hooks')
// @ts-ignore
globalThis.__ssr_start_time = performance.now()
}

const [, , ...args] = process.argv

const options = {} as Record<string, any>
Expand Down
41 changes: 40 additions & 1 deletion src/dev/server.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import type { ServerResponse } from 'http'
import { promises as fs } from 'fs'
import path from 'path'
import { performance } from 'perf_hooks'
import connect, { NextHandleFunction } from 'connect'
import {
createServer as createViteServer,
InlineConfig,
ViteDevServer,
} from 'vite'
import chalk from 'chalk'
import { getEntryPoint, getPluginOptions } from '../config'
import { buildHtmlDocument } from '../build/utils'

Expand Down Expand Up @@ -168,12 +170,20 @@ export async function createSsrServer(
}
}

const isMiddlewareMode =
// @ts-ignore
options?.middlewareMode || options?.server?.middlewareMode

return new Proxy(viteServer, {
get(target, prop, receiver) {
if (prop === 'listen') {
return async (port?: number) => {
const server = await target.listen(port)
target.config.logger.info('\n -- SSR mode\n')

if (!isMiddlewareMode) {
printServerInfo(server)
}

return server
}
}
Expand All @@ -182,3 +192,32 @@ export async function createSsrServer(
},
})
}

export function printServerInfo(server: ViteDevServer) {
const info = server.config.logger.info

let ssrReadyMessage = '\n -- SSR mode'

if (Object.prototype.hasOwnProperty.call(server, 'printUrls')) {
info(
chalk.cyan(`\n vite v${require('vite/package.json').version}`) +
chalk.green(` dev server running at:\n`),
{ clear: !server.config.logger.hasWarned }
)

// @ts-ignore
server.printUrls()

// @ts-ignore
if (globalThis.__ssr_start_time) {
ssrReadyMessage += chalk.cyan(
` ready in ${Math.round(
// @ts-ignore
performance.now() - globalThis.__ssr_start_time
)}ms.`
)
}
}

info(ssrReadyMessage + '\n')
}
2 changes: 1 addition & 1 deletion test/fixtures/react-ts-basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
"@types/node": "^16.4.7",
"@vitejs/plugin-react": "^1.0.2",
"typescript": "^4.3.2",
"vite": "^2.5.0"
"vite": "2.6.x"
}
}
2 changes: 1 addition & 1 deletion test/fixtures/vue-ts-basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@vitejs/plugin-vue": "^1.2.5",
"@vue/compiler-sfc": "^3.2.0",
"typescript": "^4.3.2",
"vite": "^2.5.0",
"vite": "2.6.x",
"vue-tsc": "^0.0.24"
}
}
152 changes: 134 additions & 18 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1257,10 +1257,107 @@ es-to-primitive@^1.2.1:
is-date-object "^1.0.1"
is-symbol "^1.0.2"

esbuild@^0.12.17:
version "0.12.25"
resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.12.25.tgz#c2131cef022cf9fe94aaa5e00110b27fc976221a"
integrity sha512-woie0PosbRSoN8gQytrdCzUbS2ByKgO8nD1xCZkEup3D9q92miCze4PqEI9TZDYAuwn6CruEnQpJxgTRWdooAg==
[email protected]:
version "0.13.4"
resolved "https://registry.yarnpkg.com/esbuild-android-arm64/-/esbuild-android-arm64-0.13.4.tgz#5178a20d2b7aba741a31c19609f9e67b346996b9"
integrity sha512-elDJt+jNyoHFId0/dKsuVYUPke3EcquIyUwzJCH17a3ERglN3A9aMBI5zbz+xNZ+FbaDNdpn0RaJHCFLbZX+fA==

[email protected]:
version "0.13.4"
resolved "https://registry.yarnpkg.com/esbuild-darwin-64/-/esbuild-darwin-64-0.13.4.tgz#7a3e66c8e1271b650541b25eed65c84f3564a69d"
integrity sha512-zJQGyHRAdZUXlRzbN7W+7ykmEiGC+bq3Gc4GxKYjjWTgDRSEly98ym+vRNkDjXwXYD3gGzSwvH35+MiHAtWvLA==

[email protected]:
version "0.13.4"
resolved "https://registry.yarnpkg.com/esbuild-darwin-arm64/-/esbuild-darwin-arm64-0.13.4.tgz#793feca6032b2a57ef291eb9b2d33768d60a49d6"
integrity sha512-r8oYvAtqSGq8HNTZCAx4TdLE7jZiGhX9ooGi5AQAey37MA6XNaP8ZNlw9OCpcgpx3ryU2WctXwIqPzkHO7a8dg==

[email protected]:
version "0.13.4"
resolved "https://registry.yarnpkg.com/esbuild-freebsd-64/-/esbuild-freebsd-64-0.13.4.tgz#294aec3c2cf4b41fb6900212fc9c33dd8fbbb4a2"
integrity sha512-u9DRGkn09EN8+lCh6z7FKle7awi17PJRBuAKdRNgSo5ZrH/3m+mYaJK2PR2URHMpAfXiwJX341z231tSdVe3Yw==

[email protected]:
version "0.13.4"
resolved "https://registry.yarnpkg.com/esbuild-freebsd-arm64/-/esbuild-freebsd-arm64-0.13.4.tgz#09fe66c751c12f9b976976b1d83f3de594cb2787"
integrity sha512-q3B2k68Uf6gfjATjcK16DqxvjqRQkHL8aPoOfj4op+lSqegdXvBacB1d8jw8PxbWJ8JHpdTLdAVUYU80kotQXA==

[email protected]:
version "0.13.4"
resolved "https://registry.yarnpkg.com/esbuild-linux-32/-/esbuild-linux-32-0.13.4.tgz#a9f0793d7bcc9cef4f4ffa4398c525877fba5839"
integrity sha512-UUYJPHSiKAO8KoN3Ls/iZtgDLZvK5HarES96aolDPWZnq9FLx4dIHM/x2z4Rxv9IYqQ/DxlPoE2Co1UPBIYYeA==

[email protected]:
version "0.13.4"
resolved "https://registry.yarnpkg.com/esbuild-linux-64/-/esbuild-linux-64-0.13.4.tgz#c0d0b4c9d62e3bbf8bdf2cece37403aa6d60fc2e"
integrity sha512-+RnohAKiiUW4UHLGRkNR1AnENW1gCuDWuygEtd4jxTNPIoeC7lbXGor7rtgjj9AdUzFgOEvAXyNNX01kJ8NueQ==

[email protected]:
version "0.13.4"
resolved "https://registry.yarnpkg.com/esbuild-linux-arm64/-/esbuild-linux-arm64-0.13.4.tgz#1292d97bfa64a08d12728f8a7837bf92776c779b"
integrity sha512-+A188cAdd6QuSRxMIwRrWLjgphQA0LDAQ/ECVlrPVJwnx+1i64NjDZivoqPYLOTkSPIKntiWwMhhf0U5/RrPHQ==

[email protected]:
version "0.13.4"
resolved "https://registry.yarnpkg.com/esbuild-linux-arm/-/esbuild-linux-arm-0.13.4.tgz#186cd9b8885ac132b9953a4a0afe668168debd10"
integrity sha512-BH5gKve4jglS7UPSsfwHSX79I5agC/lm4eKoRUEyo8lwQs89frQSRp2Xup+6SFQnxt3md5EsKcd2Dbkqeb3gPA==

[email protected]:
version "0.13.4"
resolved "https://registry.yarnpkg.com/esbuild-linux-mips64le/-/esbuild-linux-mips64le-0.13.4.tgz#42049bf72bc586817b4a51cc9e32148d13e5e807"
integrity sha512-0xkwtPaUkG5xMTFGaQPe1AadSe5QAiQuD4Gix1O9k5Xo/U8xGIkw9UFUTvfEUeu71vFb6ZgsIacfP1NLoFjWNw==

[email protected]:
version "0.13.4"
resolved "https://registry.yarnpkg.com/esbuild-linux-ppc64le/-/esbuild-linux-ppc64le-0.13.4.tgz#adf1ce2ef2302757c4383887da6ac4dd25be9d4f"
integrity sha512-E1+oJPP7A+j23GPo3CEpBhGwG1bni4B8IbTA3/3rvzjURwUMZdcN3Fhrz24rnjzdLSHmULtOE4VsbT42h1Om4Q==

[email protected]:
version "0.13.4"
resolved "https://registry.yarnpkg.com/esbuild-openbsd-64/-/esbuild-openbsd-64-0.13.4.tgz#1c8122101898c52a20c8786935cf3eb7a19b83b4"
integrity sha512-xEkI1o5HYxDzbv9jSox0EsDxpwraG09SRiKKv0W8pH6O3bt+zPSlnoK7+I7Q69tkvONkpIq5n2o+c55uq0X7cw==

[email protected]:
version "0.13.4"
resolved "https://registry.yarnpkg.com/esbuild-sunos-64/-/esbuild-sunos-64-0.13.4.tgz#4ec95faa14a60f295fe485bebffefff408739337"
integrity sha512-bjXUMcODMnB6hQicLBBmmnBl7OMDyVpFahKvHGXJfDChIi5udiIRKCmFUFIRn+AUAKVlfrofRKdyPC7kBsbvGQ==

[email protected]:
version "0.13.4"
resolved "https://registry.yarnpkg.com/esbuild-windows-32/-/esbuild-windows-32-0.13.4.tgz#3182c380487b797b04d0ec2c80c2945666869080"
integrity sha512-z4CH07pfyVY0XF98TCsGmLxKCl0kyvshKDbdpTekW9f2d+dJqn5mmoUyWhpSVJ0SfYWJg86FoD9nMbbaMVyGdg==

[email protected]:
version "0.13.4"
resolved "https://registry.yarnpkg.com/esbuild-windows-64/-/esbuild-windows-64-0.13.4.tgz#b9e995f92d81f433a04f33611e603e82f9232e69"
integrity sha512-uVL11vORRPjocGLYam67rwFLd0LvkrHEs+JG+1oJN4UD9MQmNGZPa4gBHo6hDpF+kqRJ9kXgQSeDqUyRy0tj/Q==

[email protected]:
version "0.13.4"
resolved "https://registry.yarnpkg.com/esbuild-windows-arm64/-/esbuild-windows-arm64-0.13.4.tgz#fb239532f07b764d158f4cc787178ef4c6fadb5c"
integrity sha512-vA6GLvptgftRcDcWngD5cMlL4f4LbL8JjU2UMT9yJ0MT5ra6hdZNFWnOeOoEtY4GtJ6OjZ0i+81sTqhAB0fMkg==

esbuild@^0.13.2:
version "0.13.4"
resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.13.4.tgz#ce2deb56c4fb360938311cbfc67f8e467bb6841b"
integrity sha512-wMA5eUwpavTBiNl+It6j8OQuKVh69l6z4DKDLzoTIqC+gChnPpcmqdA8WNHptUHRnfyML+mKEQPlW7Mybj8gHg==
optionalDependencies:
esbuild-android-arm64 "0.13.4"
esbuild-darwin-64 "0.13.4"
esbuild-darwin-arm64 "0.13.4"
esbuild-freebsd-64 "0.13.4"
esbuild-freebsd-arm64 "0.13.4"
esbuild-linux-32 "0.13.4"
esbuild-linux-64 "0.13.4"
esbuild-linux-arm "0.13.4"
esbuild-linux-arm64 "0.13.4"
esbuild-linux-mips64le "0.13.4"
esbuild-linux-ppc64le "0.13.4"
esbuild-openbsd-64 "0.13.4"
esbuild-sunos-64 "0.13.4"
esbuild-windows-32 "0.13.4"
esbuild-windows-64 "0.13.4"
esbuild-windows-arm64 "0.13.4"

escalade@^3.1.1:
version "3.1.1"
Expand Down Expand Up @@ -1430,7 +1527,7 @@ fs.realpath@^1.0.0:
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
integrity sha1-FQStJSMVjKpA20onh8sBQRmU6k8=

fsevents@~2.3.1, fsevents@~2.3.2:
fsevents@~2.3.2:
version "2.3.2"
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a"
integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==
Expand Down Expand Up @@ -1983,6 +2080,11 @@ nanoid@^3.1.23:
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.1.23.tgz#f744086ce7c2bc47ee0a8472574d5c78e4183a81"
integrity sha512-FiB0kzdP0FFVGDKlRLEQ1BgDzU87dy5NnzjeW9YZNt+/c3+q82EQDUwniSAUxp/F0gFNI1ZhKU1FqYsMuqZVnw==

nanoid@^3.1.28:
version "3.1.29"
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.1.29.tgz#214fb2d7a33e1a5bef4757b779dfaeb6a4e5aeb4"
integrity sha512-dW2pUSGZ8ZnCFIlBIA31SV8huOGCHb6OwzVCc7A69rb/a+SgPBwfmLvK5TKQ3INPbRkcI8a/Owo0XbiTNH19wg==

[email protected]:
version "0.6.2"
resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.2.tgz#feacf7ccf525a77ae9634436a64883ffeca346fb"
Expand Down Expand Up @@ -2163,6 +2265,11 @@ pend@~1.2.0:
resolved "https://registry.yarnpkg.com/pend/-/pend-1.2.0.tgz#7a57eb550a6783f9115331fcf4663d5c8e007a50"
integrity sha1-elfrVQpng/kRUzH89GY9XI4AelA=

picocolors@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-0.2.1.tgz#570670f793646851d1ba135996962abad587859f"
integrity sha512-cMlDqaLEqfSaW8Z7N5Jw+lyIW869EzT73/F5lhtY9cLGoVxSXznfgfXMO0Z5K0o0Q2TkTXq+0KFsdnSe3jDViA==

picomatch@^2.2.2:
version "2.2.2"
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.2.2.tgz#21f333e9b6b8eaff02468f5146ea406d345f4dad"
Expand Down Expand Up @@ -2258,7 +2365,7 @@ postcss-value-parser@^4.0.2, postcss-value-parser@^4.1.0:
resolved "https://registry.yarnpkg.com/postcss-value-parser/-/postcss-value-parser-4.1.0.tgz#443f6a20ced6481a2bda4fa8532a6e55d789a2cb"
integrity sha512-97DXOFbQJhk71ne5/Mt6cOu6yxsSfM0QGQyl0L25Gca4yGWEGJaig7l7gbCX623VqTBNGLRLaVUCnNkcedlRSQ==

postcss@^8.1.10, postcss@^8.3.6:
postcss@^8.1.10:
version "8.3.6"
resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.3.6.tgz#2730dd76a97969f37f53b9a6096197be311cc4ea"
integrity sha512-wG1cc/JhRgdqB6WHEuyLTedf3KIRuD0hG6ldkFEZNCjRxiC+3i6kkWUUbiJQayP28iwG35cEmAbe98585BYV0A==
Expand All @@ -2267,6 +2374,15 @@ postcss@^8.1.10, postcss@^8.3.6:
nanoid "^3.1.23"
source-map-js "^0.6.2"

postcss@^8.3.8:
version "8.3.9"
resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.3.9.tgz#98754caa06c4ee9eb59cc48bd073bb6bd3437c31"
integrity sha512-f/ZFyAKh9Dnqytx5X62jgjhhzttjZS7hMsohcI7HEI5tjELX/HxCy3EFhsRxyzGvrzFF+82XPvCS8T9TFleVJw==
dependencies:
nanoid "^3.1.28"
picocolors "^0.2.1"
source-map-js "^0.6.2"

prettier@^2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.4.1.tgz#671e11c89c14a4cfc876ce564106c4a6726c9f5c"
Expand Down Expand Up @@ -2489,12 +2605,12 @@ rimraf@^3.0.2:
dependencies:
glob "^7.1.3"

rollup@^2.38.5:
version "2.44.0"
resolved "https://registry.yarnpkg.com/rollup/-/rollup-2.44.0.tgz#8da324d1c4fd12beef9ae6e12f4068265b6d95eb"
integrity sha512-rGSF4pLwvuaH/x4nAS+zP6UNn5YUDWf/TeEU5IoXSZKBbKRNTCI3qMnYXKZgrC0D2KzS2baiOZt1OlqhMu5rnQ==
rollup@^2.57.0:
version "2.58.0"
resolved "https://registry.yarnpkg.com/rollup/-/rollup-2.58.0.tgz#a643983365e7bf7f5b7c62a8331b983b7c4c67fb"
integrity sha512-NOXpusKnaRpbS7ZVSzcEXqxcLDOagN6iFS8p45RkoiMqPHDLwJm758UF05KlMoCRbLBTZsPOIa887gZJ1AiXvw==
optionalDependencies:
fsevents "~2.3.1"
fsevents "~2.3.2"

sade@^1.7.3:
version "1.7.4"
Expand Down Expand Up @@ -2925,15 +3041,15 @@ vary@~1.1.2:
resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc"
integrity sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=

vite@^2.5.0:
version "2.5.3"
resolved "https://registry.yarnpkg.com/vite/-/vite-2.5.3.tgz#88d40a9efb9bec66bd87a7676c5689f35ff63742"
integrity sha512-1wMDnjflvtTTkMov8O/Xb5+w1/VW/Gw8oCf8f6dqgHn8lMOEqq0SaPtFEQeikFcOKCfSbiU0nEi0LDIx6DNsaQ==
vite@2.6.x:
version "2.6.5"
resolved "https://registry.yarnpkg.com/vite/-/vite-2.6.5.tgz#c4d25972e2f7371e682da86828722ddf5126f3d1"
integrity sha512-vavXMChDUb4Oh4YunrK9BrH5Ox74cu0eOp0VuyI/iqFz1FqbWD72So2c9I87lLL2n0+6tFPV5ijow60KrtxuZg==
dependencies:
esbuild "^0.12.17"
postcss "^8.3.6"
esbuild "^0.13.2"
postcss "^8.3.8"
resolve "^1.20.0"
rollup "^2.38.5"
rollup "^2.57.0"
optionalDependencies:
fsevents "~2.3.2"

Expand Down

0 comments on commit 08067b6

Please sign in to comment.