Skip to content

Commit 088891b

Browse files
alan-agius4clydin
authored andcommitted
refactor(@angular-devkit/build-angular): refactor NodeJsAsyncHost to use FS promises
1 parent e79e7dd commit 088891b

File tree

7 files changed

+12
-31
lines changed

7 files changed

+12
-31
lines changed

packages/angular/cli/utilities/package-tree.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@
99
import * as fs from 'fs';
1010
import { dirname, join } from 'path';
1111
import * as resolve from 'resolve';
12-
import { promisify } from 'util';
1312
import { NgAddSaveDepedency } from './package-metadata';
1413

15-
const readFile = promisify(fs.readFile);
16-
1714
interface PackageJson {
1815
name: string;
1916
version: string;
@@ -47,7 +44,7 @@ export interface PackageTreeNode {
4744

4845
export async function readPackageJson(packageJsonPath: string): Promise<PackageJson | undefined> {
4946
try {
50-
return JSON.parse((await readFile(packageJsonPath)).toString());
47+
return JSON.parse((await fs.promises.readFile(packageJsonPath)).toString());
5148
} catch {
5249
return undefined;
5350
}

packages/angular_devkit/build_angular/src/app-shell/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { BrowserBuilderOutput } from '../browser';
1818
import { Schema as BrowserBuilderSchema } from '../browser/schema';
1919
import { ServerBuilderOutput } from '../server';
2020
import { normalizeOptimization } from '../utils';
21-
import { readFile, writeFile } from '../utils/fs';
2221
import { InlineCriticalCssProcessor } from '../utils/index-file/inline-critical-css';
2322
import { augmentAppWithServiceWorker } from '../utils/service-worker';
2423
import { Spinner } from '../utils/spinner';
@@ -68,7 +67,7 @@ async function _renderUniversal(
6867
for (const outputPath of browserResult.outputPaths) {
6968
const localeDirectory = path.relative(browserResult.baseOutputPath, outputPath);
7069
const browserIndexOutputPath = path.join(outputPath, 'index.html');
71-
const indexHtml = await readFile(browserIndexOutputPath, 'utf8');
70+
const indexHtml = await fs.promises.readFile(browserIndexOutputPath, 'utf8');
7271
const serverBundlePath = await _getServerModuleBundlePath(options, context, serverResult, localeDirectory);
7372

7473
const {
@@ -115,7 +114,7 @@ async function _renderUniversal(
115114
}
116115
}
117116

118-
await writeFile(outputIndexPath, html);
117+
await fs.promises.writeFile(outputIndexPath, html);
119118

120119
if (browserOptions.serviceWorker) {
121120
await augmentAppWithServiceWorker(

packages/angular_devkit/build_angular/src/browser/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import { findCachePath } from '../utils/cache-path';
3030
import { colors } from '../utils/color';
3131
import { copyAssets } from '../utils/copy-assets';
3232
import { cachingDisabled } from '../utils/environment-options';
33-
import { mkdir, writeFile } from '../utils/fs';
3433
import { i18nInlineEmittedFiles } from '../utils/i18n-inlining';
3534
import { I18nOptions } from '../utils/i18n-options';
3635
import { FileInfo } from '../utils/index-file/augment-index-html';
@@ -702,8 +701,8 @@ export function buildWebpackBrowser(
702701
}
703702

704703
const indexOutput = path.join(outputPath, getIndexOutputFile(options.index));
705-
await mkdir(path.dirname(indexOutput), { recursive: true });
706-
await writeFile(indexOutput, content);
704+
await fs.promises.mkdir(path.dirname(indexOutput), { recursive: true });
705+
await fs.promises.writeFile(indexOutput, content);
707706
} catch (error) {
708707
spinner.fail('Index html generation failed.');
709708

packages/angular_devkit/build_angular/src/utils/fs.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

packages/angular_devkit/build_angular/src/utils/index-file/index-html-generator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
import * as fs from 'fs';
910
import { join } from 'path';
10-
import { readFile } from '../fs';
1111
import { NormalizedOptimizationOptions } from '../normalize-optimization';
1212
import { stripBom } from '../strip-bom';
1313
import { CrossOriginValue, FileInfo, augmentIndexHtml } from './augment-index-html';
@@ -94,11 +94,11 @@ export class IndexHtmlGenerator {
9494
}
9595

9696
async readAsset(path: string): Promise<string> {
97-
return readFile(path, 'utf-8');
97+
return fs.promises.readFile(path, 'utf-8');
9898
}
9999

100100
protected async readIndex(path: string): Promise<string> {
101-
return readFile(path, 'utf-8');
101+
return fs.promises.readFile(path, 'utf-8');
102102
}
103103
}
104104

packages/angular_devkit/build_angular/src/utils/index-file/inline-critical-css.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import { readFile } from '../fs';
9+
import * as fs from 'fs';
1010

1111
const Critters: typeof import('critters').default = require('critters');
1212

@@ -46,7 +46,7 @@ class CrittersExtended extends Critters {
4646
protected readFile(path: string): Promise<string> {
4747
const readAsset = this.optionsExtended.readAsset;
4848

49-
return readAsset ? readAsset(path) : readFile(path, 'utf-8');
49+
return readAsset ? readAsset(path) : fs.promises.readFile(path, 'utf-8');
5050
}
5151
}
5252

packages/angular_devkit/build_angular/src/utils/index-file/inline-fonts.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
*/
88

99
import * as cacache from 'cacache';
10+
import * as fs from 'fs';
1011
import * as https from 'https';
1112
import * as proxyAgent from 'https-proxy-agent';
1213
import { URL } from 'url';
1314
import { findCachePath } from '../cache-path';
1415
import { cachingDisabled } from '../environment-options';
15-
import { readFile } from '../fs';
1616
import { htmlRewritingStream } from './html-rewriting-stream';
1717

1818
const cacheFontsPath: string | undefined = cachingDisabled ? undefined : findCachePath('angular-build-fonts');
@@ -97,7 +97,7 @@ export class InlineFontsProcessor {
9797
if (cacheFontsPath) {
9898
const entry = await cacache.get.info(cacheFontsPath, key);
9999
if (entry) {
100-
return readFile(entry.path, 'utf8');
100+
return fs.promises.readFile(entry.path, 'utf8');
101101
}
102102
}
103103

0 commit comments

Comments
 (0)