vitrify 0.2.1 → 0.2.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.
package/dist/index.js CHANGED
@@ -308,6 +308,9 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
308
308
  if (id.includes('fastify-ssr-plugin')) {
309
309
  return 'fastify-ssr-plugin';
310
310
  }
311
+ else if (id.includes('prerender')) {
312
+ return 'prerender';
313
+ }
311
314
  else if (id.includes('node_modules')) {
312
315
  return 'vendor';
313
316
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitrify",
3
- "version": "0.2.1",
3
+ "version": "0.2.4",
4
4
  "license": "MIT",
5
5
  "author": "Stefan van Herwijnen",
6
6
  "description": "Pre-configured Vite CLI for your framework",
@@ -71,6 +71,7 @@
71
71
  "middie": "^6.0.0",
72
72
  "readline": "^1.3.0",
73
73
  "sass": "1.50.0",
74
+ "unplugin-vue-components": "^0.19.3",
74
75
  "vite": "^2.9.5",
75
76
  "vitest": "^0.9.3"
76
77
  },
@@ -83,7 +84,6 @@
83
84
  "quasar": "^2.6.6",
84
85
  "rollup": "^2.70.1",
85
86
  "typescript": "^4.6.3",
86
- "unplugin-vue-components": "^0.19.3",
87
87
  "vite": "^2.9.5",
88
88
  "vue": "^3.2.33",
89
89
  "vue-router": "^4.0.14"
@@ -103,8 +103,7 @@
103
103
  },
104
104
  "files": [
105
105
  "dist",
106
- "src/node/frameworks",
107
- "src/vite",
106
+ "src",
108
107
  "!dist/**/*.test.js",
109
108
  "!dist/**/test.js"
110
109
  ]
@@ -0,0 +1,38 @@
1
+ // import { resolve } from 'import-meta-resolve'
2
+ import { existsSync } from 'fs'
3
+
4
+ export const getPkgJsonDir = (dir: URL): URL => {
5
+ const pkgJsonPath = new URL('package.json', dir)
6
+ if (existsSync(pkgJsonPath.pathname)) {
7
+ return new URL('./', pkgJsonPath)
8
+ }
9
+ return getPkgJsonDir(new URL('..', dir))
10
+ }
11
+ export const getAppDir = () =>
12
+ getPkgJsonDir(new URL(`file://${process.cwd()}/`))
13
+ export const getCliDir = () => getPkgJsonDir(new URL('./', import.meta.url))
14
+ export const getCliViteDir = (cliDir: URL) => new URL('src/vite/', cliDir)
15
+ export const getSrcDir = (appDir: URL) => new URL('src/', appDir)
16
+ export const getCwd = () => new URL(`file://${process.cwd()}/`)
17
+ // export const quasarDir = getPkgJsonDir(new URL('./', await resolve('quasar', appDir.href)))
18
+
19
+ export const parsePath = (path: string, basePath: URL) => {
20
+ if (path) {
21
+ if (path.slice(-1) !== '/') path += '/'
22
+ if (path.startsWith('.')) {
23
+ return new URL(path, basePath)
24
+ } else if (path) {
25
+ return new URL(`file://${path}`)
26
+ }
27
+ }
28
+ return
29
+ }
30
+
31
+ export const getProjectURLs = (appDir: URL, cliDir: URL) => {
32
+ const srcDir = getSrcDir(appDir)
33
+ return {
34
+ src: (path: string) => new URL(path, srcDir),
35
+ app: (path: string) => new URL(path, appDir),
36
+ cli: (path: string) => new URL(path, cliDir)
37
+ }
38
+ }
@@ -0,0 +1,87 @@
1
+ #!/usr/bin/node --experimental-specifier-resolution=node
2
+ import { baseConfig } from '../index.js'
3
+ // import { promises as fs } from 'fs'
4
+ // import { routesToPaths } from '../helpers/routes.js'
5
+ import { build as viteBuild } from 'vite'
6
+ // import { SsrFunction } from '../vitrify-config.js'
7
+
8
+ // export const prerender = async ({
9
+ // outDir,
10
+ // templatePath,
11
+ // manifestPath,
12
+ // entryServerPath,
13
+ // injectSsrContext
14
+ // }: {
15
+ // outDir: string
16
+ // templatePath: string
17
+ // manifestPath: string
18
+ // entryServerPath: string
19
+ // injectSsrContext: SsrFunction
20
+ // }) => {
21
+ // let template
22
+ // let manifest
23
+ // const promises = []
24
+ // template = (await fs.readFile(templatePath)).toString()
25
+ // manifest = await fs.readFile(manifestPath)
26
+ // let { render, getRoutes } = await import(entryServerPath)
27
+ // const routes = await getRoutes()
28
+ // const paths = routesToPaths(routes).filter(
29
+ // (i) => !i.includes(':') && !i.includes('*')
30
+ // )
31
+ // for (let url of paths) {
32
+ // const filename =
33
+ // (url.endsWith('/') ? 'index' : url.replace(/^\//g, '')) + '.html'
34
+ // console.log(`Generating ${filename}`)
35
+ // const ssrContext = {
36
+ // req: { headers: {}, url },
37
+ // res: {}
38
+ // }
39
+ // const [appHtml, preloadLinks] = await render(url, manifest, ssrContext)
40
+
41
+ // let html = template
42
+ // .replace(`<!--preload-links-->`, preloadLinks)
43
+ // .replace(`<!--app-html-->`, appHtml)
44
+
45
+ // html = injectSsrContext(html, ssrContext)
46
+
47
+ // promises.push(fs.writeFile(outDir + filename, html, 'utf-8'))
48
+ // }
49
+ // return Promise.all(promises)
50
+ // }
51
+
52
+ export async function build(opts: {
53
+ ssr?: 'client' | 'server' | 'ssg'
54
+ base?: string
55
+ outDir?: string
56
+ appDir?: URL
57
+ publicDir?: URL
58
+ }) {
59
+ const config = await baseConfig({
60
+ command: 'build',
61
+ mode: 'production',
62
+ ssr: opts?.ssr,
63
+ appDir: opts.appDir,
64
+ publicDir: opts.publicDir
65
+ })
66
+
67
+ config.build = {
68
+ ...config.build,
69
+ minify: false,
70
+ outDir: opts.outDir,
71
+ emptyOutDir: !!opts.outDir
72
+ }
73
+
74
+ if (opts.base) {
75
+ config.define = {
76
+ ...config.define,
77
+ __BASE_URL__: `'${opts.base}'`
78
+ }
79
+ }
80
+
81
+ return viteBuild({
82
+ configFile: false,
83
+ base: opts.base,
84
+ // logLevel: 'silent',
85
+ ...config
86
+ })
87
+ }
@@ -0,0 +1,157 @@
1
+ #!/usr/bin/env node
2
+ import cac from 'cac'
3
+ import { getAppDir, parsePath } from '../app-urls.js'
4
+ import { printHttpServerUrls } from '../helpers/logger.js'
5
+ import type { ViteDevServer } from 'vite'
6
+ import type { Server } from 'net'
7
+
8
+ const cli = cac('vitrify')
9
+ cli
10
+ .command('build')
11
+ .option('-m, --mode [mode]', 'Build mode', { default: 'csr' })
12
+ .option('--base [base]', 'Base public path')
13
+ .option('--outDir [outDir]', 'Output directory')
14
+ .option('--appDir [appDir]', 'App directory')
15
+ .option('--publicDir [publicDir]', 'Public directory')
16
+ .option('--productName [productName]', 'Product name')
17
+ .action(async (options) => {
18
+ const { build } = await import('./build.js')
19
+ let appDir: URL
20
+ let prerender, ssrFunctions
21
+ if (options.appDir) {
22
+ if (options.appDir.slice(-1) !== '/') options.appDir += '/'
23
+ appDir = new URL(`file://${options.appDir}`)
24
+ } else {
25
+ appDir = getAppDir()
26
+ }
27
+
28
+ const baseOutDir =
29
+ parsePath(options.outDir, appDir) || new URL('dist/', appDir)
30
+
31
+ const args: {
32
+ base: string
33
+ appDir?: URL
34
+ publicDir?: URL
35
+ } = {
36
+ base: options.base,
37
+ appDir,
38
+ publicDir: parsePath(options.publicDir, appDir)
39
+ }
40
+
41
+ switch (options.mode) {
42
+ case 'csr':
43
+ await build({
44
+ ...args,
45
+ outDir: new URL('spa/', baseOutDir).pathname
46
+ })
47
+ break
48
+ case 'ssr':
49
+ await build({
50
+ ssr: 'client',
51
+ ...args,
52
+ outDir: new URL('ssr/client/', baseOutDir).pathname
53
+ })
54
+ await build({
55
+ ssr: 'server',
56
+ ...args,
57
+ outDir: new URL('ssr/server/', baseOutDir).pathname
58
+ })
59
+ break
60
+ case 'ssg':
61
+ await build({
62
+ ssr: 'client',
63
+ ...args,
64
+ outDir: new URL('static/', baseOutDir).pathname
65
+ })
66
+ await build({
67
+ ssr: 'server',
68
+ ...args,
69
+ outDir: new URL('ssr/server/', baseOutDir).pathname
70
+ })
71
+ ;({ prerender, ssrFunctions } = await import(
72
+ new URL('ssr/server/prerender.mjs', baseOutDir).pathname
73
+ ))
74
+ prerender({
75
+ outDir: new URL('static/', baseOutDir).pathname,
76
+ templatePath: new URL('static/index.html', baseOutDir).pathname,
77
+ manifestPath: new URL('static/ssr-manifest.json', baseOutDir)
78
+ .pathname,
79
+ entryServerPath: new URL('ssr/server/entry-server.mjs', baseOutDir)
80
+ .pathname,
81
+ ssrFunctions
82
+ })
83
+ break
84
+ default:
85
+ console.log('Invalid build mode')
86
+ break
87
+ }
88
+ })
89
+
90
+ cli
91
+ .command('dev')
92
+ .option('-m, --mode [mode]', 'Development server mode', { default: 'csr' })
93
+ .option(
94
+ '--host [host]',
95
+ 'Specify which IP addresses the server should listen on',
96
+ { default: '127.0.0.1' }
97
+ )
98
+ .option('--appDir [appDir]', 'Application directory')
99
+ .option('--publicDir [publicDir]', 'Public directory')
100
+ .action(async (options) => {
101
+ let server: Server
102
+ let vite: ViteDevServer
103
+ if (options.host === true) {
104
+ options.host = '0.0.0.0'
105
+ }
106
+ const { createServer } = await import('./dev.js')
107
+ const cwd = (await import('../app-urls.js')).getCwd()
108
+ switch (options.mode) {
109
+ case 'ssr':
110
+ ;({ server, vite } = await createServer({
111
+ mode: 'ssr',
112
+ host: options.host,
113
+ appDir: parsePath(options.appDir, cwd),
114
+ publicDir: parsePath(options.publicDir, cwd)
115
+ }))
116
+ break
117
+ default:
118
+ ;({ server, vite } = await createServer({
119
+ host: options.host,
120
+ appDir: parsePath(options.appDir, cwd),
121
+ publicDir: parsePath(options.publicDir, cwd)
122
+ }))
123
+ break
124
+ }
125
+ console.log('Dev server running at:')
126
+ printHttpServerUrls(server, vite.config)
127
+ })
128
+
129
+ cli.command('test').action(async (options) => {
130
+ const { test } = await import('./test.js')
131
+
132
+ let appDir: URL
133
+ if (options.appDir) {
134
+ if (options.appDir.slice(-1) !== '/') options.appDir += '/'
135
+ appDir = new URL(`file://${options.appDir}`)
136
+ } else {
137
+ appDir = getAppDir()
138
+ }
139
+ await test({
140
+ appDir
141
+ })
142
+ })
143
+
144
+ cli.command('run <file>').action(async (file, options) => {
145
+ const { run } = await import('./run.js')
146
+ const filePath = new URL(file, `file://${process.cwd()}/`)
147
+ await run(filePath.pathname)
148
+ })
149
+
150
+ // Default
151
+ cli.command('').action((command, options) => {
152
+ cli.outputHelp()
153
+ })
154
+
155
+ cli.help()
156
+
157
+ cli.parse()
@@ -0,0 +1,138 @@
1
+ import type { ViteDevServer, LogLevel } from 'vite'
2
+ import { searchForWorkspaceRoot } from 'vite'
3
+ import { baseConfig } from '../index.js'
4
+ import type { Server } from 'net'
5
+ import type { FastifyInstance } from 'fastify/types/instance'
6
+ import fastify from 'fastify'
7
+ import { readFileSync } from 'fs'
8
+
9
+ export async function createServer({
10
+ port = 3000,
11
+ logLevel = 'info',
12
+ mode = 'csr',
13
+ framework = 'vue',
14
+ host,
15
+ appDir,
16
+ publicDir
17
+ }: {
18
+ port?: number
19
+ logLevel?: LogLevel
20
+ mode?: 'csr' | 'ssr'
21
+ framework?: 'vue'
22
+ host?: string
23
+ appDir?: URL
24
+ publicDir?: URL
25
+ }) {
26
+ const { getAppDir, getCliDir, getCwd } = await import('../app-urls.js')
27
+ const cwd = getCwd()
28
+ const cliDir = getCliDir()
29
+ if (!appDir) appDir = getAppDir()
30
+ const { fastifySsrPlugin } = await import(
31
+ `../${framework}/fastify-ssr-plugin.js`
32
+ )
33
+
34
+ /**
35
+ * @type {import('vite').ViteDevServer}
36
+ */
37
+ const config = await baseConfig({
38
+ ssr: mode === 'ssr' ? 'server' : undefined,
39
+ command: 'dev',
40
+ mode: 'development',
41
+ appDir,
42
+ publicDir
43
+ })
44
+ config.logLevel = logLevel
45
+ config.server = {
46
+ port,
47
+ middlewareMode: mode === 'ssr' ? 'ssr' : undefined,
48
+ fs: {
49
+ allow: [
50
+ searchForWorkspaceRoot(process.cwd()),
51
+ searchForWorkspaceRoot(appDir.pathname),
52
+ searchForWorkspaceRoot(cliDir.pathname)
53
+ // appDir.pathname,
54
+ ]
55
+ },
56
+ watch: {
57
+ // During tests we edit the files too fast and sometimes chokidar
58
+ // misses change events, so enforce polling for consistency
59
+ usePolling: true,
60
+ interval: 100
61
+ },
62
+ host
63
+ }
64
+ const vite = await (
65
+ await import('vite')
66
+ ).createServer({
67
+ configFile: false,
68
+ ...config
69
+ })
70
+ const { productName = 'Product name' } = JSON.parse(
71
+ readFileSync(new URL('package.json', appDir).pathname, {
72
+ encoding: 'utf-8'
73
+ })
74
+ )
75
+
76
+ let app: ViteDevServer | FastifyInstance
77
+ let server: Server
78
+ if (mode === 'ssr') {
79
+ console.log('SSR mode')
80
+ app = fastify()
81
+ await app.register(fastifySsrPlugin, {
82
+ appDir,
83
+ cliDir,
84
+ vite,
85
+ productName
86
+ })
87
+ // await app.register(middie)
88
+ // app.use(vite.middlewares)
89
+
90
+ // app.get('*', async (req, res) => {
91
+ // try {
92
+ // // const url = req.originalUrl
93
+ // const url = req.raw.url
94
+ // let template
95
+ // let render
96
+ // const ssrContext = {
97
+ // req,
98
+ // res
99
+ // }
100
+ // // always read fresh template in dev
101
+ // // template = readFileSync(resolve('index.html'), 'utf-8')
102
+ // template = readFileSync(new URL('index.html', cliDir)).toString()
103
+
104
+ // // template = await vite.transformIndexHtml(url, template)
105
+ // const entryUrl = new URL('ssr/entry-server.ts', cliDir).pathname
106
+ // render = (await vite.ssrLoadModule(entryUrl)).render
107
+ // let manifest
108
+ // // TODO: https://github.com/vitejs/vite/issues/2282
109
+ // try {
110
+ // manifest = {}
111
+ // } catch (e) {
112
+ // manifest = {}
113
+ // }
114
+
115
+ // const [appHtml, preloadLinks] = await render(url, manifest, ssrContext)
116
+ // const html = template
117
+ // .replace(`<!--preload-links-->`, preloadLinks)
118
+ // .replace(`<!--app-html-->`, appHtml)
119
+ // .replace('<!--product-name-->', productName)
120
+
121
+ // res.code(200)
122
+ // res.type('text/html')
123
+ // res.send(html)
124
+ // // res.status(200).set({ 'Content-Type': 'text/html' }).end(html)
125
+ // } catch (e: any) {
126
+ // console.error(e.stack)
127
+ // vite && vite.ssrFixStacktrace(e)
128
+ // res.code(500)
129
+ // res.send(e.stack)
130
+ // }
131
+ // })
132
+ await app.listen(port || 3000, host)
133
+ server = app.server
134
+ } else {
135
+ server = (await vite.listen()).httpServer as Server
136
+ }
137
+ return { server, vite }
138
+ }
@@ -0,0 +1,47 @@
1
+ import { promises as fs } from 'fs'
2
+ import readline from 'readline'
3
+ import { getAppDir, getCliDir, getProjectURLs } from '../app-urls.js'
4
+
5
+ const rl = readline.createInterface({
6
+ input: process.stdin,
7
+ output: process.stdout
8
+ })
9
+
10
+ export interface VitrifyContext {
11
+ vitrify: {
12
+ version: string
13
+ }
14
+ projectURLs: ReturnType<typeof getProjectURLs>
15
+ }
16
+
17
+ export async function run(filePath: string) {
18
+ const { run } = await import(filePath)
19
+ const appDir = getAppDir()
20
+ const cliDir = getCliDir()
21
+ const projectURLs = getProjectURLs(appDir, cliDir)
22
+ const pkg = JSON.parse(
23
+ (await fs.readFile(projectURLs.cli('package.json'), 'utf-8')).toString()
24
+ )
25
+
26
+ if (!run)
27
+ throw new Error(
28
+ `${filePath} does not have an export named run. Aborting...`
29
+ )
30
+
31
+ rl.question(
32
+ `
33
+ The script ${filePath}
34
+ will now be executed by vitrify.
35
+ Make sure you trust the content of this script before proceeding.
36
+ Press enter to proceed or CTRL+C to abort.`,
37
+ async (answer) => {
38
+ await run({
39
+ vitrify: {
40
+ version: pkg.version
41
+ },
42
+ resolve: projectURLs
43
+ })
44
+ rl.close()
45
+ }
46
+ )
47
+ }
@@ -0,0 +1,24 @@
1
+ import { startVitest } from 'vitest/node'
2
+ import { baseConfig } from '../index.js'
3
+ export async function test(opts: { appDir: URL }) {
4
+ const config = await baseConfig({
5
+ appDir: opts.appDir,
6
+ command: 'test',
7
+ mode: 'development'
8
+ })
9
+
10
+ await startVitest(
11
+ [],
12
+ {
13
+ root: opts.appDir.pathname,
14
+ dir: opts.appDir.pathname,
15
+
16
+ globals: true,
17
+ environment: 'happy-dom'
18
+ // include: [
19
+ // `${opts.appDir.pathname}**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}`
20
+ // ]
21
+ },
22
+ config
23
+ )
24
+ }
@@ -0,0 +1,142 @@
1
+ // https://github.com/quasarframework/quasar/blob/dev/app/lib/helpers/logger.js
2
+ import chalk from 'chalk'
3
+ const { bgGreen, green, inverse, bgRed, red, bgYellow, yellow } = chalk
4
+ import readline from 'readline'
5
+ import type { AddressInfo, Server } from 'net'
6
+ import type { ResolvedConfig, Logger } from 'vite'
7
+ import os from 'os'
8
+ import type { Hostname } from '../helpers/utils.js'
9
+ import { resolveHostname } from '../helpers/utils.js'
10
+
11
+ /**
12
+ * Main approach - App CLI related
13
+ */
14
+
15
+ const dot = '•'
16
+ const banner = 'App ' + dot
17
+ const greenBanner = green(banner)
18
+ const redBanner = red(banner)
19
+ const yellowBanner = yellow(banner)
20
+
21
+ export const clearConsole = process.stdout.isTTY
22
+ ? () => {
23
+ // Fill screen with blank lines. Then move to 0 (beginning of visible part) and clear it
24
+ const blank = '\n'.repeat(process.stdout.rows)
25
+ console.log(blank)
26
+ readline.cursorTo(process.stdout, 0, 0)
27
+ readline.clearScreenDown(process.stdout)
28
+ }
29
+ : () => {}
30
+
31
+ export const log = function (msg?: string) {
32
+ console.log(msg ? ` ${greenBanner} ${msg}` : '')
33
+ }
34
+
35
+ export const warn = function (msg?: string, pill?: string) {
36
+ if (msg !== void 0) {
37
+ const pillBanner = pill !== void 0 ? bgYellow.black('', pill, '') + ' ' : ''
38
+
39
+ console.warn(` ${yellowBanner} ⚠️ ${pillBanner}${msg}`)
40
+ } else {
41
+ console.warn()
42
+ }
43
+ }
44
+
45
+ export const fatal = function (msg?: string, pill?: string) {
46
+ if (msg !== void 0) {
47
+ const pillBanner = pill !== void 0 ? errorPill(pill) + ' ' : ''
48
+
49
+ console.error(`\n ${redBanner} ⚠️ ${pillBanner}${msg}\n`)
50
+ } else {
51
+ console.error()
52
+ }
53
+
54
+ process.exit(1)
55
+ }
56
+
57
+ /**
58
+ * Extended approach - Compilation status & pills
59
+ */
60
+
61
+ export const successPill = (msg?: string) => bgGreen.black('', msg, '')
62
+ export const infoPill = (msg?: string) => inverse('', msg, '')
63
+ export const errorPill = (msg?: string) => bgRed.white('', msg, '')
64
+ export const warningPill = (msg?: string) => bgYellow.black('', msg, '')
65
+
66
+ export const success = function (msg?: string, title = 'SUCCESS') {
67
+ console.log(` ${greenBanner} ${successPill(title)} ${green(dot + ' ' + msg)}`)
68
+ }
69
+ export const getSuccess = function (msg?: string, title?: string) {
70
+ return ` ${greenBanner} ${successPill(title)} ${green(dot + ' ' + msg)}`
71
+ }
72
+
73
+ export const info = function (msg?: string, title = 'INFO') {
74
+ console.log(` ${greenBanner} ${infoPill(title)} ${green(dot)} ${msg}`)
75
+ }
76
+ export const getInfo = function (msg?: string, title?: string) {
77
+ return ` ${greenBanner} ${infoPill(title)} ${green(dot)} ${msg}`
78
+ }
79
+
80
+ export const error = function (msg?: string, title = 'ERROR') {
81
+ console.log(` ${redBanner} ${errorPill(title)} ${red(dot + ' ' + msg)}`)
82
+ }
83
+ export const getError = function (msg?: string, title = 'ERROR') {
84
+ return ` ${redBanner} ${errorPill(title)} ${red(dot + ' ' + msg)}`
85
+ }
86
+
87
+ export const warning = function (msg?: string, title = 'WARNING') {
88
+ console.log(
89
+ ` ${yellowBanner} ${warningPill(title)} ${yellow(dot + ' ' + msg)}`
90
+ )
91
+ }
92
+ export const getWarning = function (msg?: string, title = 'WARNING') {
93
+ return ` ${yellowBanner} ${warningPill(title)} ${yellow(dot + ' ' + msg)}`
94
+ }
95
+
96
+ export function printHttpServerUrls(
97
+ server: Server,
98
+ config: ResolvedConfig
99
+ ): void {
100
+ const address = server.address()
101
+ const isAddressInfo = (x: any): x is AddressInfo => x?.address
102
+ if (isAddressInfo(address)) {
103
+ const hostname = resolveHostname(config.server.host)
104
+ const protocol = config.server.https ? 'https' : 'http'
105
+ printServerUrls(
106
+ hostname,
107
+ protocol,
108
+ address.port,
109
+ config.base,
110
+ config.logger.info
111
+ )
112
+ }
113
+ }
114
+
115
+ function printServerUrls(
116
+ hostname: Hostname,
117
+ protocol: string,
118
+ port: number,
119
+ base: string,
120
+ info: Logger['info']
121
+ ): void {
122
+ if (hostname.host === '127.0.0.1') {
123
+ const url = `${protocol}://${hostname.name}:${chalk.bold(port)}${base}`
124
+ info(` > Local: ${chalk.cyan(url)}`)
125
+ if (hostname.name !== '127.0.0.1') {
126
+ info(` > Network: ${chalk.dim('use `--host` to expose')}`)
127
+ }
128
+ } else {
129
+ Object.values(os.networkInterfaces())
130
+ .flatMap((nInterface) => nInterface ?? [])
131
+ .filter((detail) => detail && detail.address && detail.family === 'IPv4')
132
+ .map((detail) => {
133
+ const type = detail.address.includes('127.0.0.1')
134
+ ? 'Local: '
135
+ : 'Network: '
136
+ const host = detail.address.replace('127.0.0.1', hostname.name)
137
+ const url = `${protocol}://${host}:${chalk.bold(port)}${base}`
138
+ return ` > ${type} ${chalk.cyan(url)}`
139
+ })
140
+ .forEach((msg) => info(msg))
141
+ }
142
+ }