X Tutup
Skip to content

Commit b05db7e

Browse files
committed
Merge branch 'master' into ianc/moving-lts-to-wbt
2 parents 084e345 + a6a76a7 commit b05db7e

File tree

7 files changed

+87
-54
lines changed

7 files changed

+87
-54
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/gulp-core-build",
5+
"comment": "Improve watch() so that it will automatically begin excecuting and it will not exit if there is a failure on the initial build",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@microsoft/gulp-core-build",
10+
"email": "nickpape@users.noreply.github.com"
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/web-library-build",
5+
"comment": "Fix an issue with 'gulp serve' where an initial build error would stop watch from continuing",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@microsoft/web-library-build",
10+
"email": "nickpape@users.noreply.github.com"
11+
}

core-build/gulp-core-build/src/index.ts

Lines changed: 56 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { IBuildConfig } from './IBuildConfig';
1414
import { CleanTask } from './tasks/CleanTask';
1515
import { args } from './State';
1616
export { IExecutable } from './IExecutable';
17+
import { log } from './logging';
1718
import { initialize as initializeLogging, markTaskCreationTime, generateGulpError, setWatchMode } from './logging';
1819
import { getFlagValue, setConfigDefaults } from './config';
1920
import * as gulp from 'gulp';
@@ -188,57 +189,71 @@ export function watch(watchMatch: string | string[], task: IExecutable): IExecut
188189
let shouldRerunWatch: boolean = false;
189190
let lastError: boolean = undefined;
190191

192+
const successMessage: string = 'Build succeeded';
193+
const failureMessage: string = 'Build failed';
194+
191195
return {
192196
execute: (buildConfig: IBuildConfig): Promise<void> => {
193-
194-
setWatchMode();
195-
buildConfig.gulp.watch(watchMatch, _runWatch);
196-
197-
function _runWatch(): void {
198-
if (isWatchRunning) {
199-
shouldRerunWatch = true;
200-
} else {
201-
isWatchRunning = true;
202-
203-
_executeTask(task, buildConfig)
204-
.then(() => {
205-
if (buildConfig.showToast && lastError) {
206-
lastError = undefined;
207-
208-
notifier.notify({
209-
title: 'Build succeeded',
210-
message: packageJSON.name,
211-
icon: buildConfig.buildSuccessIconPath
212-
});
213-
}
214-
_finalizeWatch();
215-
})
216-
.catch((error) => {
217-
if (buildConfig.showToast) {
197+
return new Promise<void>(() => {
198+
199+
function _runWatch(): Promise<void> {
200+
if (isWatchRunning) {
201+
shouldRerunWatch = true;
202+
} else {
203+
isWatchRunning = true;
204+
205+
return _executeTask(task, buildConfig)
206+
.then(() => {
207+
if (lastError) {
208+
lastError = undefined;
209+
210+
if (buildConfig.showToast) {
211+
notifier.notify({
212+
title: successMessage,
213+
message: packageJSON.name,
214+
icon: buildConfig.buildSuccessIconPath
215+
});
216+
} else {
217+
log(successMessage);
218+
}
219+
}
220+
return _finalizeWatch();
221+
})
222+
.catch((error) => {
218223
if (!lastError || lastError !== error) {
219224
lastError = error;
220-
notifier.notify({
221-
title: 'Build failed',
222-
message: error,
223-
icon: buildConfig.buildErrorIconPath
224-
});
225+
226+
if (buildConfig.showToast) {
227+
notifier.notify({
228+
title: failureMessage,
229+
message: error,
230+
icon: buildConfig.buildErrorIconPath
231+
});
232+
} else {
233+
log(failureMessage);
234+
}
225235
}
226-
}
227-
_finalizeWatch();
228-
});
236+
237+
return _finalizeWatch();
238+
});
239+
}
229240
}
230-
}
231241

232-
function _finalizeWatch(): void {
233-
isWatchRunning = false;
242+
function _finalizeWatch(): Promise<void> {
243+
isWatchRunning = false;
234244

235-
if (shouldRerunWatch) {
236-
shouldRerunWatch = false;
237-
_runWatch();
245+
if (shouldRerunWatch) {
246+
shouldRerunWatch = false;
247+
return _runWatch();
248+
}
249+
return Promise.resolve();
238250
}
239-
}
240251

241-
return Promise.resolve();
252+
setWatchMode();
253+
buildConfig.gulp.watch(watchMatch, _runWatch);
254+
255+
_runWatch();
256+
});
242257
}
243258
};
244259
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"copyTo": {
3-
"src": [
4-
"preCopyTest.ts"
3+
"lib": [
4+
"preCopyTest.js"
55
]
66
}
77
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default function preCopyTest(): void;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22
// See LICENSE in the project root for license information.
33

4-
export default function preCopyTest(): void {
4+
export default function preCopyTest() {
55
/* no-op */
66
}

core-build/web-library-build/src/index.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
task,
1212
watch,
1313
setConfig,
14-
14+
getConfig
1515
} from '@microsoft/gulp-core-build';
1616
import { apiExtractor, typescript, tslint, text } from '@microsoft/gulp-core-build-typescript';
1717
import { sass } from '@microsoft/gulp-core-build-sass';
@@ -39,7 +39,7 @@ const sourceMatch: string[] = [
3939
'!src/**/*.scss.ts'
4040
];
4141

42-
const PRODUCTION = process.argv.indexOf('--production') !== -1 || process.argv.indexOf('--ship') !== -1;
42+
const PRODUCTION = !!getConfig().args['production'] || !!getConfig().args['ship'];
4343
setConfig({
4444
production: PRODUCTION,
4545
shouldWarningsFailBuild: PRODUCTION
@@ -65,14 +65,9 @@ task('test-watch', watch(sourceMatch, testTasks));
6565

6666
// For watch scenarios like serve, make sure to exclude generated files from src (like *.scss.ts.)
6767
task('serve',
68-
serial(
69-
bundleTasks,
70-
serve,
71-
postProcessSourceMapsTask,
72-
watch(
73-
sourceMatch, serial(preCopy, sass, compileTsTasks,
74-
postCopy, webpack, postProcessSourceMapsTask, reload)
75-
)
68+
watch(
69+
sourceMatch, serial(preCopy, sass, compileTsTasks,
70+
postCopy, webpack, postProcessSourceMapsTask, reload)
7671
)
7772
);
7873

0 commit comments

Comments
 (0)
X Tutup