Skip to content

Commit fbdb784

Browse files
FrozenPandazvsavkin
authored andcommittedOct 4, 2018
fix(builders): fix node builders on windows
1 parent 08c994a commit fbdb784

File tree

4 files changed

+68
-11
lines changed

4 files changed

+68
-11
lines changed
 

‎packages/builders/src/node/build/node-build.builder.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import {
44
BuilderConfiguration,
55
BuilderContext
66
} from '@angular-devkit/architect';
7-
import { virtualFs, Path } from '@angular-devkit/core';
7+
import { getSystemPath } from '@angular-devkit/core';
88
import { WebpackBuilder } from '@angular-devkit/build-webpack';
99

1010
import { Observable } from 'rxjs';
11-
import { Stats, writeFileSync } from 'fs';
11+
import { writeFileSync } from 'fs';
1212
import { getWebpackConfig, OUT_FILENAME } from './webpack/config';
1313
import { resolve } from 'path';
1414
import { map } from 'rxjs/operators';
@@ -29,7 +29,7 @@ export interface BuildNodeBuilderOptions {
2929
statsJson?: boolean;
3030
extractLicenses?: boolean;
3131

32-
root?: Path;
32+
root?: string;
3333
}
3434

3535
export interface FileReplacement {
@@ -45,12 +45,11 @@ export default class BuildNodeBuilder
4545
implements Builder<BuildNodeBuilderOptions> {
4646
webpackBuilder: WebpackBuilder;
4747

48-
private get root() {
49-
return this.context.workspace.root;
50-
}
48+
root: string;
5149

5250
constructor(private context: BuilderContext) {
5351
this.webpackBuilder = new WebpackBuilder(this.context);
52+
this.root = getSystemPath(this.context.workspace.root);
5453
}
5554

5655
run(

‎packages/builders/src/node/build/webpack/config.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getWebpackConfig } from './config';
22
import { BuildNodeBuilderOptions } from '../node-build.builder';
3-
import { normalize } from '@angular-devkit/core';
3+
import { normalize, getSystemPath } from '@angular-devkit/core';
44

55
import * as ts from 'typescript';
66
import { LicenseWebpackPlugin } from 'license-webpack-plugin';
@@ -17,7 +17,7 @@ describe('getWebpackConfig', () => {
1717
tsConfig: 'tsconfig.json',
1818
externalDependencies: 'all',
1919
fileReplacements: [],
20-
root: normalize('/root')
20+
root: getSystemPath(normalize('/root'))
2121
};
2222
});
2323

‎packages/builders/src/node/execute/node-execute.builder.spec.ts

+54
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,60 @@ describe('NodeExecuteBuilder', () => {
109109
expect(fork).toHaveBeenCalledTimes(2);
110110
});
111111

112+
it('should log errors from killing the process', () => {
113+
treeKill.mockImplementation((pid, signal, callback) => {
114+
callback(new Error('Error Message'));
115+
});
116+
const loggerError = spyOn(logger, 'error');
117+
expect(
118+
builder.run({
119+
root: normalize('/root'),
120+
projectType: 'application',
121+
builder: '@nrwl/builders:node-execute',
122+
options: testOptions
123+
})
124+
).toBeObservable(
125+
cold('--a--b--a', {
126+
a: {
127+
success: true,
128+
outfile: 'outfile.js'
129+
},
130+
b: {
131+
success: false,
132+
outfile: 'outfile.js'
133+
}
134+
})
135+
);
136+
expect(loggerError.calls.argsFor(1)).toEqual(['Error Message']);
137+
});
138+
139+
it('should log errors from killing the process on windows', () => {
140+
treeKill.mockImplementation((pid, signal, callback) => {
141+
callback([new Error('error'), '', 'Error Message']);
142+
});
143+
const loggerError = spyOn(logger, 'error');
144+
expect(
145+
builder.run({
146+
root: normalize('/root'),
147+
projectType: 'application',
148+
builder: '@nrwl/builders:node-execute',
149+
options: testOptions
150+
})
151+
).toBeObservable(
152+
cold('--a--b--a', {
153+
a: {
154+
success: true,
155+
outfile: 'outfile.js'
156+
},
157+
b: {
158+
success: false,
159+
outfile: 'outfile.js'
160+
}
161+
})
162+
);
163+
expect(loggerError.calls.argsFor(1)).toEqual(['Error Message']);
164+
});
165+
112166
it('should build the application and start the built file with options', () => {
113167
expect(
114168
builder.run({

‎packages/builders/src/node/execute/node-execute.builder.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,14 @@ export class NodeExecuteBuilder implements Builder<NodeExecuteBuilderOptions> {
7272
const observableTreeKill = bindCallback(treeKill);
7373
return observableTreeKill(this.subProcess.pid, 'SIGTERM').pipe(
7474
tap(err => {
75+
this.subProcess = null;
7576
if (err) {
76-
throw err;
77-
} else {
78-
this.subProcess = null;
77+
if (Array.isArray(err) && err[0] && err[2]) {
78+
const errorMessage = err[2];
79+
this.context.logger.error(errorMessage);
80+
} else if (err.message) {
81+
this.context.logger.error(err.message);
82+
}
7983
}
8084
})
8185
);

0 commit comments

Comments
 (0)
Please sign in to comment.