Skip to content

Commit

Permalink
fix(ivy): ngcc - use spaces in overwritten package.json content for…
Browse files Browse the repository at this point in the history
… readability (#30831)

When ngcc processes an entrypoint, it updates `package.json` with
metadata about the processed format. Previously, it overwrote the
`package.json` with the stringified JSON object without spaces. This
made the file difficult to read (for example when looking at the file
while debugging an ngcc failure).

This commit fixes it by using spaces in the new `package.json` content.

PR Close #30831
  • Loading branch information
gkalpak authored and mhevery committed Jun 6, 2019
1 parent 5a7bcd1 commit 65f2010
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions integration/ngcc/test.sh
Expand Up @@ -14,23 +14,23 @@ if [[ $? != 0 ]]; then exit 1; fi
# Did it add the appropriate build markers?

# - esm2015
grep '"__processed_by_ivy_ngcc__":[^}]*"esm2015":"' node_modules/@angular/common/package.json
cat node_modules/@angular/common/package.json | awk 'ORS=" "' | grep '"__processed_by_ivy_ngcc__":[^}]*"esm2015": "'
if [[ $? != 0 ]]; then exit 1; fi

# - fesm2015
grep '"__processed_by_ivy_ngcc__":[^}]*"fesm2015":"' node_modules/@angular/common/package.json
cat node_modules/@angular/common/package.json | awk 'ORS=" "' | grep '"__processed_by_ivy_ngcc__":[^}]*"fesm2015": "'
if [[ $? != 0 ]]; then exit 1; fi
grep '"__processed_by_ivy_ngcc__":[^}]*"es2015":"' node_modules/@angular/common/package.json
cat node_modules/@angular/common/package.json | awk 'ORS=" "' | grep '"__processed_by_ivy_ngcc__":[^}]*"es2015": "'
if [[ $? != 0 ]]; then exit 1; fi

# - esm5
grep '"__processed_by_ivy_ngcc__":[^}]*"esm5":"' node_modules/@angular/common/package.json
cat node_modules/@angular/common/package.json | awk 'ORS=" "' | grep '"__processed_by_ivy_ngcc__":[^}]*"esm5": "'
if [[ $? != 0 ]]; then exit 1; fi

# - fesm5
grep '"__processed_by_ivy_ngcc__":[^}]*"module":"' node_modules/@angular/common/package.json
cat node_modules/@angular/common/package.json | awk 'ORS=" "' | grep '"__processed_by_ivy_ngcc__":[^}]*"module": "'
if [[ $? != 0 ]]; then exit 1; fi
grep '"__processed_by_ivy_ngcc__":[^}]*"fesm5":"' node_modules/@angular/common/package.json
cat node_modules/@angular/common/package.json | awk 'ORS=" "' | grep '"__processed_by_ivy_ngcc__":[^}]*"fesm5": "'
if [[ $? != 0 ]]; then exit 1; fi

# Did it replace the PRE_R3 markers correctly?
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler-cli/ngcc/src/packages/build_marker.ts
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import {writeFileSync} from 'fs';
import {writeFileSync, writeFile} from 'fs';

import {AbsoluteFsPath} from '../../../src/ngtsc/path';

Expand Down Expand Up @@ -53,5 +53,5 @@ export function markAsProcessed(
format: EntryPointJsonProperty) {
if (!packageJson.__processed_by_ivy_ngcc__) packageJson.__processed_by_ivy_ngcc__ = {};
packageJson.__processed_by_ivy_ngcc__[format] = NGCC_VERSION;
writeFileSync(packageJsonPath, JSON.stringify(packageJson), 'utf8');
writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf8');
}

0 comments on commit 65f2010

Please sign in to comment.