Skip to content

Commit

Permalink
fix: catch error
Browse files Browse the repository at this point in the history
  • Loading branch information
liximomo committed Sep 9, 2022
1 parent 75efdce commit 0fbaf5d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
4 changes: 2 additions & 2 deletions packages/error-overlay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"umd"
],
"scripts": {
"dev": "pnpm run iframe-dev && run-p watch:*",
"iframe-dev": "cross-env NODE_ENV=development rollup -c rollup.config.iframe.js -w",
"dev": "run-p watch:*",
"watch:iframe": "cross-env NODE_ENV=development rollup -c rollup.config.iframe.js -w",
"watch:cjs": "tsc -p tsconfig.build.json -m commonjs --outDir lib -w",
"watch:umd": "cross-env NODE_ENV=development rollup -c rollup.config.js -w",
"prebuild": "rimraf lib",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { RawSourceMap } from 'source-map';
import dataUriToBuffer, { MimeBuffer } from 'data-uri-to-buffer';
import * as path from 'path';
import type webpack from '@shuvi/toolpack/lib/webpack';
import type { webpack } from '@shuvi/toolpack/lib/webpack';

import { getSourceMapUrl } from './getSourceMapUrl';
import { getModuleById } from './getModuleById';
Expand Down
20 changes: 15 additions & 5 deletions test/utils/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function buildFixture(
configOverrides: ShuviConfig = {},
spawnOptions: SpawnOptions = {}
) {
return shuviSync(
const res = shuviSync(
'build',
[
path.isAbsolute(fixture) ? fixture : resolveFixture(fixture),
Expand All @@ -55,6 +55,10 @@ export function buildFixture(
],
spawnOptions
);
if (res.status !== 0) {
throw res.error || new Error(res.stderr);
}
return res;
}

export async function launchFixtureAtCurrentProcess(
Expand Down Expand Up @@ -103,7 +107,7 @@ async function launchShuvi(
envOverrides: Partial<NodeJS.ProcessEnv>,
handleStdoutStderr: IHandleStdoutStderr
): Promise<ChildProcess> {
return new Promise(resolve => {
return new Promise((resolve, reject) => {
// dynamic NODE_SERVER like EXPRESS, KOA default SHUVI
const NODE_SERVER = process.env.NODE_SERVER;
const spawnOptions: SpawnOptions = {
Expand All @@ -114,7 +118,12 @@ async function launchShuvi(
}
// At first, build when production mode
if (!isDev) {
buildFixture(projectPath, configOverrides, spawnOptions);
try {
buildFixture(projectPath, configOverrides, spawnOptions);
} catch (error) {
reject(error);
return;
}
}
let shuviProcess: ChildProcess;
if (NODE_SERVER) {
Expand All @@ -125,7 +134,8 @@ async function launchShuvi(
NODE_SERVER.toLocaleLowerCase()
);
} catch (error) {
throw error;
reject(error);
return;
}

shuviProcess = spawn('node', [NODE_SERVER_SOURCE], {
Expand Down Expand Up @@ -158,10 +168,10 @@ async function launchShuvi(
// In this case, it will be a little more complex to spy on `console.log`.
console.log(data);
// We could only listen to the console output to ensure that devServer is ready
handleStdoutStderr.onStdout && handleStdoutStderr.onStdout(data);
if (data.includes('Ready on')) {
resolve(shuviProcess);
}
handleStdoutStderr.onStdout && handleStdoutStderr.onStdout(data);
});
}
if (shuviProcess.stderr) {
Expand Down

0 comments on commit 0fbaf5d

Please sign in to comment.