Skip to content

Commit

Permalink
fix(build): ts-compile not reporting failures
Browse files Browse the repository at this point in the history
  • Loading branch information
pimenovoleg committed Sep 30, 2018
1 parent af66572 commit ba38135
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 30 deletions.
5 changes: 3 additions & 2 deletions tools/packages/compile-entry-point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { sync as glob } from 'glob';
import { join } from 'path';

import { BuildPackage } from './build-package';
import { ngcCompile } from './ngc-compile';
import { tsCompile } from './ts-compile';


let nextId = 0;
Expand All @@ -24,7 +24,7 @@ export async function compileEntryPoint(buildPackage: BuildPackage, tsConfigName
ngcFlags.push('--outDir', es5OutputPath, '--target', 'ES5');
}

return ngcCompile(ngcFlags).catch(() => {
return tsCompile('ngc', ngcFlags).catch(() => {
const error = chalk.default.red(`Failed to compile ${secondaryEntryPoint} using ${entryPointTSConfigPath}`);
/* tslint:disable-next-line:no-console */
console.error(error);
Expand Down Expand Up @@ -73,6 +73,7 @@ function addImportAs(packageName: string, outputPath: string, secondaryEntryPoin
glob(join(path, '**/*.+(metadata.json)')).forEach((metadataPath) => {
const metadata = JSON.parse(readFileSync(metadataPath, 'utf-8'));

// tslint:disable-next-line
metadata[0]['importAs'] = `@ptsecurity/${packageName}/${secondaryEntryPoint}`;

writeFileSync(metadataPath, JSON.stringify(metadata), 'utf-8');
Expand Down
26 changes: 0 additions & 26 deletions tools/packages/ngc-compile.ts

This file was deleted.

31 changes: 31 additions & 0 deletions tools/packages/ts-compile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as chalk from 'chalk';
import { spawn } from 'child_process';

import {resolve as resolvePath } from 'path';


/* tslint:disable:no-console */
/**
* Spawns a child process that compiles TypeScript using the specified compiler binary.
* @param binary Binary name that will be used for TS compilation.
* @param flags Command-line flags to be passed to binary.
* @returns Promise that resolves/rejects when the child process exits.
*/
export function tsCompile(binary: 'tsc' | 'ngc', flags: string[]) {

// tslint:disable-next-line
return new Promise((resolve, reject) => {
const binaryPath = resolvePath('./node_modules/.bin/ngc');
const childProcess = spawn(binaryPath, flags, {shell: true});

// Pipe stdout and stderr from the child process.
childProcess.stdout.on('data', (data: string | Buffer) => console.log(`${data}`));
childProcess.stderr.on('data', (data: string | Buffer) => console.error(chalk.default.red(`${data}`)));
childProcess.on('exit', (exitCode: number) => {
// tslint:disable-next-line
exitCode === 0 ? resolve() : reject(`${binary} compilation failure`);
});
});
}

/* tslint:enable:no-console */
7 changes: 5 additions & 2 deletions tools/packages/version-placeholders.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { spawnSync } from 'child_process';
import { readFileSync, writeFileSync } from 'fs';
import { platform } from 'os';

import { buildConfig } from './build-config';
import { spawnSync } from 'child_process';


/** Variable that is set to the string for version placeholders. */
const versionPlaceholderText = '0.0.0-PLACEHOLDER';
Expand All @@ -26,7 +28,7 @@ export function replaceVersionPlaceholders(packageDir: string) {

// Walk through every file that contains version placeholders and replace those with the current
// version of the root package.json file.
files.forEach(filePath => {
files.forEach((filePath) => {
const fileContent = readFileSync(filePath, 'utf-8')
.replace(ngVersionPlaceholderRegex, buildConfig.angularVersion)
.replace(versionPlaceholderRegex, buildConfig.projectVersion);
Expand All @@ -38,6 +40,7 @@ export function replaceVersionPlaceholders(packageDir: string) {
/** Finds all files in the specified package dir where version placeholders are included. */
function findFilesWithPlaceholders(packageDir: string): string[] {
const findCommand = buildPlaceholderFindCommand(packageDir);

return spawnSync(findCommand.binary, findCommand.args).stdout
.toString()
.split(/[\n\r]/)
Expand Down

0 comments on commit ba38135

Please sign in to comment.