From 6aa3ce4f0550bb51ef96fb8a74c2a4a57190f729 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 23 May 2018 21:56:35 -0400 Subject: [PATCH] make stdout etc available via api --- package.json | 1 - src/api/dev.ts | 24 ++++++++++++------------ src/api/interfaces.ts | 3 +++ 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index a32377a..e57859d 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,6 @@ "files": [ "*.js", "*.ts.js", - "api", "runtime", "webpack", "sapper", diff --git a/src/api/dev.ts b/src/api/dev.ts index 6a9aff9..6ce2a33 100644 --- a/src/api/dev.ts +++ b/src/api/dev.ts @@ -10,7 +10,7 @@ import prettyMs from 'pretty-ms'; import { locations } from '../config'; import { EventEmitter } from 'events'; import { create_routes, create_main_manifests, create_compilers, create_serviceworker_manifest } from '../core'; -import * as events from '../interfaces'; +import * as events from './interfaces'; export function dev(opts) { return new Watcher(opts); @@ -143,6 +143,10 @@ class Watcher extends EventEmitter { fs.writeFileSync(path.join(dest, 'server_info.json'), JSON.stringify(info, null, ' ')); this.deferreds.client.promise.then(() => { + this.dev_server.send({ + status: 'completed' + }); + const restart = () => { ports.wait(this.port).then(this.deferreds.server.fulfil); }; @@ -158,7 +162,13 @@ class Watcher extends EventEmitter { cwd: process.cwd(), env: Object.assign({ PORT: this.port - }, process.env) + }, process.env), + stdio: ['ipc'] + }); + + this.emit('ready', { + port: this.port, + process: this.proc }); }); } @@ -186,16 +196,6 @@ class Watcher extends EventEmitter { const client_files = info.assets.map((chunk: { name: string }) => `client/${chunk.name}`); - this.deferreds.server.promise.then(() => { - this.dev_server.send({ - status: 'completed' - }); - - this.emit('ready', { - port: this.port - }); - }); - create_serviceworker_manifest({ routes: create_routes(), client_files diff --git a/src/api/interfaces.ts b/src/api/interfaces.ts index 9daef0a..623ae63 100644 --- a/src/api/interfaces.ts +++ b/src/api/interfaces.ts @@ -1,5 +1,8 @@ +import * as child_process from 'child_process'; + export type ReadyEvent = { port: number; + process: child_process.ChildProcess; }; export type ErrorEvent = {