(
commandOptions: CommandOptions,
{
isDev: _isDev,
isWatch: _isWatch,
preparePackages: _preparePackages,
}: {isDev?: boolean; isWatch?: boolean; preparePackages?: boolean} = {},
)
| 255 | } |
| 256 | |
| 257 | export async function startServer( |
| 258 | commandOptions: CommandOptions, |
| 259 | { |
| 260 | isDev: _isDev, |
| 261 | isWatch: _isWatch, |
| 262 | preparePackages: _preparePackages, |
| 263 | }: {isDev?: boolean; isWatch?: boolean; preparePackages?: boolean} = {}, |
| 264 | ): Promise<SnowpackDevServer> { |
| 265 | const {config} = commandOptions; |
| 266 | const isDev = _isDev ?? config.mode !== 'production'; |
| 267 | const isWatch = _isWatch ?? true; |
| 268 | const isPreparePackages = _preparePackages ?? true; |
| 269 | const pkgSource = getPackageSource(config); |
| 270 | if (isPreparePackages) { |
| 271 | await pkgSource.prepare(); |
| 272 | logger.info(colors.bold('Ready!')); |
| 273 | } |
| 274 | let serverStart = performance.now(); |
| 275 | const {port: defaultPort, hostname, open, openUrl} = config.devOptions; |
| 276 | const messageBus = new EventEmitter(); |
| 277 | const PACKAGE_PATH_PREFIX = path.posix.join(config.buildOptions.metaUrlPath, 'pkg/'); |
| 278 | const PACKAGE_LINK_PATH_PREFIX = path.posix.join(config.buildOptions.metaUrlPath, 'link/'); |
| 279 | let port: number | undefined; |
| 280 | let warnedDeprecatedPackageImport = new Set(); |
| 281 | if (defaultPort !== 0) { |
| 282 | port = await getPort(defaultPort); |
| 283 | // Reset the clock if we had to wait for the user prompt to select a new port. |
| 284 | if (port !== defaultPort) { |
| 285 | serverStart = performance.now(); |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | // Fill in any command-specific plugin methods. |
| 290 | for (const p of config.plugins) { |
| 291 | p.markChanged = (fileLoc) => { |
| 292 | knownETags.clear(); |
| 293 | onWatchEvent(fileLoc); |
| 294 | }; |
| 295 | } |
| 296 | |
| 297 | if (isWatch && config.devOptions.output === 'dashboard' && process.stdout.isTTY) { |
| 298 | startDashboard(messageBus, config); |
| 299 | } else { |
| 300 | // "stream": Log relevent events to the console. |
| 301 | messageBus.on(paintEvent.WORKER_MSG, ({id, msg}) => { |
| 302 | logger.info(msg.trim(), {name: id}); |
| 303 | }); |
| 304 | } |
| 305 | |
| 306 | const symlinkDirectories = new Map<string, Promise<any>>(); |
| 307 | const inMemoryBuildCache = new Map<string, FileBuilder>(); |
| 308 | let fileToUrlMapping = new OneToManyMap(); |
| 309 | const excludeGlobs = [ |
| 310 | ...config.exclude, |
| 311 | ...(config.mode === 'test' ? [] : config.testOptions.files), |
| 312 | ]; |
| 313 | |
| 314 | const foundExcludeMatch = picomatch(excludeGlobs, {ignore: '**/node_modules/**'}); |
no test coverage detected