| 87 | } |
| 88 | |
| 89 | export const startDevServer: StartDevServer = async opts => { |
| 90 | const { entrypoint, workPath, config, meta = {}, publicDir } = opts; |
| 91 | const entrypointPath = join(workPath, entrypoint); |
| 92 | |
| 93 | if (meta.syncDependencies) { |
| 94 | const gray = '\x1b[90m'; |
| 95 | const reset = '\x1b[0m'; |
| 96 | const syncMessage = `${gray}Synchronizing dependencies...${reset}\n`; |
| 97 | if (opts.onStdout) { |
| 98 | opts.onStdout(Buffer.from(syncMessage)); |
| 99 | } else { |
| 100 | console.log(syncMessage); |
| 101 | } |
| 102 | |
| 103 | await syncDependencies(workPath, opts.onStdout, opts.onStderr); |
| 104 | } |
| 105 | |
| 106 | const project = new Project(); |
| 107 | const staticConfig = getConfig(project, entrypointPath); |
| 108 | const vercelConfigFile = opts.files['vercel.json']; |
| 109 | let bunVersion: BunVersion | undefined; |
| 110 | try { |
| 111 | if (vercelConfigFile?.type === 'FileFsRef') { |
| 112 | const vercelConfigContents = await fsp.readFile( |
| 113 | vercelConfigFile.fsPath, |
| 114 | 'utf8' |
| 115 | ); |
| 116 | if (vercelConfigContents) { |
| 117 | try { |
| 118 | const vercelConfig = JSON.parse(vercelConfigContents); |
| 119 | if (vercelConfig.bunVersion) { |
| 120 | bunVersion = getSupportedBunVersion(vercelConfig.bunVersion); |
| 121 | } |
| 122 | } catch { |
| 123 | // Ignore |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 | } catch { |
| 128 | // Ignore |
| 129 | } |
| 130 | const runtime = bunVersion ? 'bun' : 'node'; |
| 131 | |
| 132 | if (config.middleware === true && typeof meta.requestUrl === 'string') { |
| 133 | // Middleware is a catch-all for all paths unless a `matcher` property is defined |
| 134 | const matchers = new RegExp(getRegExpFromMatchers(staticConfig?.matcher)); |
| 135 | |
| 136 | const parsed = new URL(meta.requestUrl, 'http://localhost'); |
| 137 | if (!matchers.test(parsed.pathname)) { |
| 138 | // If the "matchers" doesn't say to handle this |
| 139 | // path then skip middleware invocation |
| 140 | return null; |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | const entryDir = dirname(entrypointPath); |
| 145 | const ext = extname(entrypoint); |
| 146 |
nothing calls this directly
no test coverage detected